Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mp_filtercheck.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_filtercheck macro
4
5 <h4> SAS Macros </h4>
6 @li mp_filtercheck.sas
7 @li mp_assertdsobs.sas
8 @li mp_assert.sas
9
10**/
11
12
13/* valid filter */
14data work.inds;
15 infile datalines4 dsd;
16 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
17 OPERATOR_NM:$10. RAW_VALUE:$4000.;
18datalines4;
19AND,AND,1,AGE,=,12
20AND,AND,1,SEX,<=,"'M'"
21AND,OR,2,Name,NOT IN,"('Jane','Alfred')"
22AND,OR,2,Weight,>=,77.7
23AND,OR,2,Weight,NE,77.7
24;;;;
25run;
26
27%mp_filtercheck(work.inds,
28 targetds=sashelp.class,
29 outds=work.badrecords,
30 abort=NO
31)
32%let syscc=0;
33%mp_assertdsobs(work.badrecords,
34 desc=Valid filter query,
35 test=EMPTY,
36 outds=work.test_results
37)
38
39/* invalid column */
40data work.inds;
41 infile datalines4 dsd;
42 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
43 OPERATOR_NM:$10. RAW_VALUE:$4000.;
44datalines4;
45AND,AND,1,invalid,=,12
46AND,AND,1,SEX,<=,"'M'"
47AND,OR,2,Name,NOT IN,"('Jane','Alfred')"
48AND,OR,2,Weight,>=,7
49;;;;
50run;
51%mp_filtercheck(work.inds,
52 targetds=sashelp.class,
53 outds=work.badrecords,
54 abort=NO
55)
56%let syscc=0;
57%mp_assertdsobs(work.badrecords,
58 desc=Invalid column name,
59 test=HASOBS,
60 outds=work.test_results
61)
62
63/* invalid raw value */
64data work.inds;
65 infile datalines4 dsd;
66 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
67 OPERATOR_NM:$10. RAW_VALUE:$4000.;
68datalines4;
69AND,OR,2,Name,NOT IN,"(''''Jane','Alfred')"
70;;;;
71run;
72
73%mp_filtercheck(work.inds,
74 targetds=sashelp.class,
75 outds=work.badrecords,
76 abort=NO
77)
78%let syscc=0;
79%mp_assertdsobs(work.badrecords,
80 desc=Invalid raw value,
81 test=HASOBS,
82 outds=work.test_results
83)
84
85/* Code injection - column name */
86data work.inds;
87 infile datalines4 dsd;
88 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
89 OPERATOR_NM:$10. RAW_VALUE:$4000.;
90datalines4;
91AND,AND,1,%abort,=,12
92AND,OR,2,Weight,>=,7
93;;;;
94run;
95
96%mp_filtercheck(work.inds,
97 targetds=sashelp.class,
98 outds=work.badrecords,
99 abort=NO
100)
101%let syscc=0;
102%mp_assertdsobs(work.badrecords,
103 desc=Code injection - column name,
104 test=HASOBS,
105 outds=work.test_results
106)
107
108/* Code injection - raw values*/
109data work.inds;
110 infile datalines4 dsd;
111 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
112 OPERATOR_NM:$10. RAW_VALUE:$4000.;
113datalines4;
114AND,AND,1,age,=,;;%abort
115;;;;
116run;
117%mp_filtercheck(work.inds,
118 targetds=sashelp.class,
119 outds=work.badrecords,
120 abort=NO
121)
122%let syscc=0;
123%mp_assertdsobs(work.badrecords,
124 desc=Code injection - raw value abort,
125 test=HASOBS,
126 outds=work.test_results
127)
128
129/* Supply variables with incorrect types */
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:8;
134datalines4;
135AND,AND,1,age,=,0
136;;;;
137run;
138%let syscc=0;
139%mp_filtercheck(work.inds,
140 targetds=sashelp.class,
141 outds=work.badrecords,
142 abort=NO
143)
144%mp_assert(iftrue=(&syscc=42),
145 desc=Throw error if RAW_VALUE is incorrect,
146 outds=work.test_results
147)
148%let syscc=0;