Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mp_filtervalidate.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_filtervalidate macro
4
5 <h4> SAS Macros </h4>
6 @li mp_filtergenerate.sas
7 @li mp_filtervalidate.sas
8 @li mp_assertdsobs.sas
9 @li mp_assert.sas
10
11**/
12
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_filtergenerate(work.inds,outref=myfilter)
27%mp_filtervalidate(myfilter,sashelp.class,outds=work.results,abort=NO)
28%mp_assertdsobs(work.results,
29 desc=Valid filter,
30 test=EMPTY,
31 outds=work.test_results
32)
33
34/* empty filter (return all records) */
35data work.inds;
36 infile datalines4 dsd;
37 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
38 OPERATOR_NM:$10. RAW_VALUE:$4000.;
39datalines4;
40;;;;
41run;
42%mp_filtergenerate(work.inds,outref=myfilter)
43%mp_filtervalidate(myfilter,sashelp.class,outds=work.results,abort=NO)
44%mp_assertdsobs(work.results,
45 desc=Empty filter,
46 test=EMPTY,
47 outds=work.test_results
48)
49
50
51
52/* invalid filter - char var, num val */
53data work.inds;
54 infile datalines4 dsd;
55 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
56 OPERATOR_NM:$10. RAW_VALUE:$4000.;
57datalines4;
58AND,AND,1,SEX,NE,2
59;;;;
60run;
61%mp_filtergenerate(work.inds,outref=myfilter)
62%mp_filtervalidate(myfilter,sashelp.class,outds=work.results,abort=NO)
63%let syscc=0;
64%let test3=0;
65data _null_;
66 set work.results;
67 if REASON_CD=:'VALIDATION_ERROR' then call symputx('test3',1);
68 putlog (_all_)(=);
69 stop;
70run;
71%mp_assert(
72 iftrue=(&test3=1),
73 desc=Checking char var could not receive num val,
74 outds=work.test_results
75)
76
77/* invalid filter - num var, char val */
78data work.inds;
79 infile datalines4 dsd;
80 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
81 OPERATOR_NM:$10. RAW_VALUE:$4000.;
82datalines4;
83AND,AND,1,age,NE,"'M'"
84;;;;
85run;
86%mp_filtergenerate(work.inds,outref=myfilter)
87%mp_filtervalidate(myfilter,sashelp.class,outds=work.results,abort=NO)
88%let syscc=0;
89%let test4=0;
90data _null_;
91 set work.results;
92 if REASON_CD=:'VALIDATION_ERROR' then call symputx('test4',1);
93 putlog (_all_)(=);
94 stop;
95run;
96%mp_assert(
97 iftrue=(&test4=1),
98 desc=Checking num var could not receive char val,
99 outds=work.test_results
100)