Macros for SAS Application Developers
https://github.com/sasjs/core
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 */
14 data work.class ;
15 length name $8 sex $1 age height weight 8;
16 infile cards dsd;
17 input Name:$char. Sex :$char. Age Height Weight;
18 datalines4;
19 Alfred,M,14,69,112.5
20 Alice,F,13,56.5,84
21 Barbara,F,13,65.3,98
22 Carol,F,14,62.8,102.5
23 Henry,M,14,63.5,102.5
24 James,M,12,57.3,83
25 Jane,F,12,59.8,84.5
26 Janet,F,15,62.5,112.5
27 Jeffrey,M,13,62.5,84
28 John,M,12,59,99.5
29 Joyce,F,11,51.3,50.5
30 Judy,F,14,64.3,90
31 Louise,F,12,56.3,77
32 Mary,F,15,66.5,112
33 Philip,M,16,72,150
34 Robert,M,12,64.8,128
35 Ronald,M,15,67,133
36 Thomas,M,11,57.5,85
37 William,M,15,66.5,112
38 ;;;;
39 run;
40 
41 libname 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 */
49 data 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.;
53 datalines4;
54 AND,AND,1,AGE,=,12
55 AND,AND,1,SEX,<=,"'M'"
56 AND,OR,2,Name,NOT IN,"('Jane','Alfred')"
57 AND,OR,2,Weight,>=,77.7
58 AND,OR,2,Weight,NE,77.7
59 AND,AND,3,age,NOT IN,"(.a,.b,.)"
60 AND,AND,3,age,NOT IN,"(.A)"
61 AND,AND,4,Name,=,"'Jeremiah'"
62 ;;;;
63 run;
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 */
86 proc sql noprint;
87 select 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 */
111 proc sql noprint;
112 select 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 )