Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_sortinplace.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_sortinplace.test.sas
4
5 <h4> SAS Macros </h4>
6 @li mp_sortinplace.sas
7 @li mp_assert.sas
8 @li mp_assertdsobs.sas
9 @li mp_assertmodel.sas
10 @li mp_getconstraints.sas
11
12**/
13
14
15/** Test 1 - regular usage */
16proc sql;
17create table work.example as
18 select * from sashelp.classfit;
19alter table work.example
20 add constraint pk primary key(name);
21
22data work.example_before;
23 set work.example;
24run;
25proc sort data=work.example_before;
26 by name;
27run;
28
29%mp_sortinplace(work.example)
30
31%mp_assertmodel(work.example,base=work.example_before,key=name,
32 desc=Sort preserves column model and primary key)
33
34%mp_getconstraints(lib=work,ds=example,outds=work.testme)
35
36%mp_assertdsobs(work.testme,
37 desc=Test1 - check constraints recreated,
38 test=EQUALS 1,
39 outds=work.test_results
40)
41
42%let test1=0;
43data _null_;
44 set work.example;
45 call symputx('test1',name);
46 stop;
47run;
48%mp_assert(
49 iftrue=(
50 %str(&test1)=%str(Alfred)
51 ),
52 desc=Check if sort was appplied,
53 outds=work.test_results
54)
55
56proc compare base=work.example_before compare=work.example noprint;
57run;
58%let sort_compare=&sysinfo;
59%mp_assert(
60 iftrue=(&sort_compare=0),
61 desc=Check all observations and values match the sorted input,
62 outds=work.test_results
63)
64
65/** Test 2 - table without PK */
66proc sql;
67create table work.example2 as
68 select * from sashelp.classfit;
69%mp_sortinplace(work.example2)
70%mp_assert(
71 iftrue=(
72 %str(&syscc)=%str(0)
73 ),
74 desc=Ensure no errors when no key exists,
75 outds=work.test_results
76)
77
78%let test2=0;
79data _null_;
80 set work.example2;
81 call symputx('test2',name);
82 stop;
83run;
84%mp_assert(
85 iftrue=(
86 %str(&test2)=%str(Alfred)
87 ),
88 desc=Check if sort was appplied when no index exists,
89 outds=work.test_results
90)