Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mp_filtergenerate.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_filtergenerate macro
4
5 <h4> SAS Macros </h4>
6 @li mp_filtergenerate.sas
7 @li mp_filtercheck.sas
8 @li mp_assertdsobs.sas
9
10**/
11
12options source2;
13
14/* valid filter */
15data work.inds;
16 infile datalines4 dsd;
17 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
18 OPERATOR_NM:$10. RAW_VALUE:$4000.;
19datalines4;
20AND,AND,1,AGE,>,5
21AND,AND,1,SEX,NE,"'M'"
22AND,OR,2,Name,NOT IN,"('Jane','Janet')"
23AND,OR,2,Weight,>=,84.6
24;;;;
25run;
26%mp_filtercheck(work.inds,targetds=sashelp.class)
27%mp_filtergenerate(work.inds,outref=myfilter)
28data work.test;
29 set sashelp.class;
30 where %inc myfilter;;
31run;
32%mp_assertdsobs(work.test,
33 desc=Valid filter,
34 test=EQUALS 8,
35 outds=work.test_results
36)
37
38/* empty filter (return all records) */
39data work.inds;
40 infile datalines4 dsd;
41 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
42 OPERATOR_NM:$10. RAW_VALUE:$4000.;
43datalines4;
44;;;;
45run;
46%mp_filtercheck(work.inds,targetds=sashelp.class)
47%mp_filtergenerate(work.inds,outref=myfilter)
48data work.test;
49 set sashelp.class;
50 where %inc myfilter;;
51run;
52%mp_assertdsobs(work.test,
53 desc=Empty filter (return all records) ,
54 test=EQUALS 19,
55 outds=work.test_results
56)
57
58/* single line filter */
59data work.inds;
60 infile datalines4 dsd;
61 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
62 OPERATOR_NM:$10. RAW_VALUE:$4000.;
63datalines4;
64AND,OR,2,Name,IN,"('Jane','Janet')"
65;;;;
66run;
67%mp_filtercheck(work.inds,targetds=sashelp.class)
68%mp_filtergenerate(work.inds,outref=myfilter)
69data work.test;
70 set sashelp.class;
71 where %inc myfilter;;
72run;
73%mp_assertdsobs(work.test,
74 desc=Single line filter ,
75 test=EQUALS 2,
76 outds=work.test_results
77)
78
79/* single line 2 group filter */
80data work.inds;
81 infile datalines4 dsd;
82 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
83 OPERATOR_NM:$10. RAW_VALUE:$4000.;
84datalines4;
85OR,OR,2,Name,IN,"('Jane','Janet')"
86OR,OR,3,Name,IN,"('James')"
87;;;;
88run;
89%mp_filtercheck(work.inds,targetds=sashelp.class)
90%mp_filtergenerate(work.inds,outref=myfilter)
91data work.test;
92 set sashelp.class;
93 where %inc myfilter;;
94run;
95%mp_assertdsobs(work.test,
96 desc=Single line 2 group filter ,
97 test=EQUALS 3,
98 outds=work.test_results
99)
100
101/* filter with nothing returned */
102data work.inds;
103 infile datalines4 dsd;
104 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
105 OPERATOR_NM:$10. RAW_VALUE:$4000.;
106datalines4;
107AND,OR,2,Name,IN,"('Jane','Janet')"
108AND,OR,3,Name,IN,"('James')"
109;;;;
110run;
111%mp_filtercheck(work.inds,targetds=sashelp.class)
112%mp_filtergenerate(work.inds,outref=myfilter)
113data work.test;
114 set sashelp.class;
115 where %inc myfilter;;
116run;
117%mp_assertdsobs(work.test,
118 desc=Filter with nothing returned,
119 test=EQUALS 0,
120 outds=work.test_results
121)
122