Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
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/* set up test data */
15data work.class ;
16length name $8 sex $1 age height weight 8;
17infile cards dsd;
18input Name:$char. Sex :$char. Age Height Weight;
19datalines4;
20Alfred,M,14,69,112.5
21Alice,F,13,56.5,84
22Barbara,F,13,65.3,98
23Carol,F,14,62.8,102.5
24Henry,M,14,63.5,102.5
25James,M,12,57.3,83
26Jane,F,12,59.8,84.5
27Janet,F,15,62.5,112.5
28Jeffrey,M,13,62.5,84
29John,M,12,59,99.5
30Joyce,F,11,51.3,50.5
31Judy,F,14,64.3,90
32Louise,F,12,56.3,77
33Mary,F,15,66.5,112
34Philip,M,16,72,150
35Robert,M,12,64.8,128
36Ronald,M,15,67,133
37Thomas,M,11,57.5,85
38William,M,15,66.5,112
39;;;;
40run;
41
42/* valid filter */
43data work.inds;
44 infile datalines4 dsd;
45 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
46 OPERATOR_NM:$10. RAW_VALUE:$4000.;
47datalines4;
48AND,AND,1,AGE,>,5
49AND,AND,1,SEX,NE,"'M'"
50AND,OR,2,Name,NOT IN,"('Jane','Janet')"
51AND,OR,2,Weight,>=,84.6
52;;;;
53run;
54%mp_filtercheck(work.inds,targetds=work.class)
55%mp_filtergenerate(work.inds,outref=myfilter)
56data work.test;
57 set work.class;
58 where %inc myfilter;;
59run;
60%mp_assertdsobs(work.test,
61 desc=Valid filter,
62 test=EQUALS 8,
63 outds=work.test_results
64)
65
66/* empty filter (return all records) */
67data work.inds;
68 infile datalines4 dsd;
69 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
70 OPERATOR_NM:$10. RAW_VALUE:$4000.;
71datalines4;
72;;;;
73run;
74%mp_filtercheck(work.inds,targetds=work.class)
75%mp_filtergenerate(work.inds,outref=myfilter)
76data work.test;
77 set work.class;
78 where %inc myfilter;;
79run;
80%mp_assertdsobs(work.test,
81 desc=Empty filter (return all records) ,
82 test=EQUALS 19,
83 outds=work.test_results
84)
85
86/* single line filter */
87data work.inds;
88 infile datalines4 dsd;
89 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
90 OPERATOR_NM:$10. RAW_VALUE:$4000.;
91datalines4;
92AND,OR,2,Name,IN,"('Jane','Janet')"
93;;;;
94run;
95%mp_filtercheck(work.inds,targetds=work.class)
96%mp_filtergenerate(work.inds,outref=myfilter)
97data work.test;
98 set work.class;
99 where %inc myfilter;;
100run;
101%mp_assertdsobs(work.test,
102 desc=Single line filter ,
103 test=EQUALS 2,
104 outds=work.test_results
105)
106
107/* single line 2 group filter */
108data work.inds;
109 infile datalines4 dsd;
110 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
111 OPERATOR_NM:$10. RAW_VALUE:$4000.;
112datalines4;
113OR,OR,2,Name,IN,"('Jane','Janet')"
114OR,OR,3,Name,IN,"('James')"
115;;;;
116run;
117%mp_filtercheck(work.inds,targetds=work.class)
118%mp_filtergenerate(work.inds,outref=myfilter)
119data work.test;
120 set work.class;
121 where %inc myfilter;;
122run;
123%mp_assertdsobs(work.test,
124 desc=Single line 2 group filter ,
125 test=EQUALS 3,
126 outds=work.test_results
127)
128
129/* filter with nothing returned */
130data work.inds;
131 infile datalines4 dsd;
132 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
133 OPERATOR_NM:$10. RAW_VALUE:$4000.;
134datalines4;
135AND,OR,2,Name,IN,"('Jane','Janet')"
136AND,OR,3,Name,IN,"('James')"
137;;;;
138run;
139%mp_filtercheck(work.inds,targetds=work.class)
140%mp_filtergenerate(work.inds,outref=myfilter)
141data work.test;
142 set work.class;
143 where %inc myfilter;;
144run;
145%mp_assertdsobs(work.test,
146 desc=Filter with nothing returned,
147 test=EQUALS 0,
148 outds=work.test_results
149)
150