Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
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 @li mp_assertscope.sas
11
12**/
13
14data work.class ;
15length name $8 sex $1 age height weight 8;
16infile cards dsd;
17input Name:$char. Sex :$char. Age Height Weight;
18datalines4;
19Alfred,M,14,69,112.5
20Alice,F,13,56.5,84
21Barbara,F,13,65.3,98
22Carol,F,14,62.8,102.5
23Henry,M,14,63.5,102.5
24James,M,12,57.3,83
25Jane,F,12,59.8,84.5
26Janet,F,15,62.5,112.5
27Jeffrey,M,13,62.5,84
28John,M,12,59,99.5
29Joyce,F,11,51.3,50.5
30Judy,F,14,64.3,90
31Louise,F,12,56.3,77
32Mary,F,15,66.5,112
33Philip,M,16,72,150
34Robert,M,12,64.8,128
35Ronald,M,15,67,133
36Thomas,M,11,57.5,85
37William,M,15,66.5,112
38;;;;
39run;
40
41/* valid filter */
42data work.inds;
43 infile datalines4 dsd;
44 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
45 OPERATOR_NM:$10. RAW_VALUE:$4000.;
46datalines4;
47AND,AND,1,AGE,>,5
48AND,AND,1,SEX,NE,"'M'"
49AND,OR,2,Name,NOT IN,"('Jane','Janet')"
50AND,OR,2,Weight,>=,84.6
51AND,AND,3,age,=,.a
52AND,AND,4,weight,NE,._
53;;;;
54run;
55%mp_filtergenerate(work.inds,outref=myfilter)
56
57%mp_assertscope(SNAPSHOT)
58%mp_filtervalidate(myfilter,work.class,outds=work.results,abort=NO)
59%mp_assertscope(COMPARE)
60
61%mp_assertdsobs(work.results,
62 desc=Valid filter,
63 test=EMPTY,
64 outds=work.test_results
65)
66
67/* empty filter (return all records) */
68data work.inds;
69 infile datalines4 dsd;
70 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
71 OPERATOR_NM:$10. RAW_VALUE:$4000.;
72datalines4;
73;;;;
74run;
75%mp_filtergenerate(work.inds,outref=myfilter)
76%mp_filtervalidate(myfilter,work.class,outds=work.results,abort=NO)
77%mp_assertdsobs(work.results,
78 desc=Empty filter,
79 test=EMPTY,
80 outds=work.test_results
81)
82
83
84
85/* invalid filter - char var, num val */
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,SEX,NE,2
92;;;;
93run;
94%mp_filtergenerate(work.inds,outref=myfilter)
95%mp_filtervalidate(myfilter,work.class,outds=work.results,abort=NO)
96%let syscc=0;
97%let test3=0;
98data _null_;
99 set work.results;
100 if REASON_CD=:'VALIDATION_ERROR' then call symputx('test3',1);
101 putlog (_all_)(=);
102 stop;
103run;
104%mp_assert(
105 iftrue=(&test3=1),
106 desc=Checking char var could not receive num val,
107 outds=work.test_results
108)
109
110/* invalid filter - num var, char val */
111data work.inds;
112 infile datalines4 dsd;
113 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
114 OPERATOR_NM:$10. RAW_VALUE:$4000.;
115datalines4;
116AND,AND,1,age,NE,"'M'"
117;;;;
118run;
119%mp_filtergenerate(work.inds,outref=myfilter)
120%mp_filtervalidate(myfilter,work.class,outds=work.results,abort=NO)
121%let syscc=0;
122%let test4=0;
123data _null_;
124 set work.results;
125 if REASON_CD=:'VALIDATION_ERROR' then call symputx('test4',1);
126 putlog (_all_)(=);
127 stop;
128run;
129%mp_assert(
130 iftrue=(&test4=1),
131 desc=Checking num var could not receive char val,
132 outds=work.test_results
133)