Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_filterstore.test.1.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_filterstore macro
4
5 <h4> SAS Macros </h4>
6 @li mp_coretable.sas
7 @li mp_filterstore.sas
8 @li mp_assertdsobs.sas
9 @li mp_assert.sas
10
11**/
12
13/* set up test data */
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
41libname permlib (work);
42
43%mp_coretable(LOCKTABLE,libds=permlib.locktable)
44%mp_coretable(FILTER_SUMMARY,libds=permlib.filtsum)
45%mp_coretable(FILTER_DETAIL,libds=permlib.filtdet)
46%mp_coretable(MAXKEYTABLE,libds=permlib.maxkey)
47
48/* valid filter */
49data work.inds;
50 infile datalines4 dsd;
51 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
52 OPERATOR_NM:$12. RAW_VALUE:$4000.;
53datalines4;
54AND,AND,1,AGE,=,12
55AND,AND,1,SEX,<=,"'M'"
56AND,OR,2,Name,NOT IN,"('Jane','Alfred')"
57AND,OR,2,Weight,>=,77.7
58AND,OR,2,Weight,NE,77.7
59AND,AND,3,age,NOT IN,"(.a,.b,.)"
60AND,AND,3,age,NOT IN,"(.A)"
61AND,AND,4,Name,=,"'Jeremiah'"
62;;;;
63run;
64
65%mp_filterstore(libds=work.class,
66 queryds=work.inds,
67 filter_summary=permlib.filtsum,
68 filter_detail=permlib.filtdet,
69 lock_table=permlib.locktable,
70 maxkeytable=permlib.maxkey,
71 outresult=work.result,
72 outquery=work.query,
73 mdebug=1
74)
75%mp_assert(iftrue=(&syscc=0),
76 desc=Ensure macro runs without errors,
77 outds=work.test_results
78)
79/* ensure only one record created */
80%mp_assertdsobs(permlib.filtsum,
81 desc=Initial query,
82 test=ATMOST 1,
83 outds=work.test_results
84)
85/* check RK is correct */
86proc sql noprint;
87select max(filter_rk) into: test1 from work.result;
88%mp_assert(iftrue=(&test1=1),
89 desc=Ensure filter rk is correct,
90 outds=work.test_results
91)
92
93/* Test 2 - load same table again and ensure we get the same RK */
94%mp_filterstore(libds=work.class,
95 queryds=work.inds,
96 filter_summary=permlib.filtsum,
97 filter_detail=permlib.filtdet,
98 lock_table=permlib.locktable,
99 maxkeytable=permlib.maxkey,
100 outresult=work.result,
101 outquery=work.query,
102 mdebug=1
103)
104/* ensure only one record created */
105%mp_assertdsobs(permlib.filtsum,
106 desc=Initial query - same obs,
107 test=ATMOST 1,
108 outds=work.test_results
109)
110/* check RK is correct */
111proc sql noprint;
112select max(filter_rk) into: test2 from work.result;
113%mp_assert(iftrue=(&test2=1),
114 desc=Ensure filter rk is correct for second run,
115 outds=work.test_results
116)