Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_filterstore.test.3.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mp_filterstore macro with a separate validation target
4
5 @details A filter may reference a variable that only exists in a view - for
6 example a computed column. In that case the validation target differs from
7 the table the filter is stored against.
8
9 <h4> SAS Macros </h4>
10 @li mp_assert.sas
11 @li mp_assertdsobs.sas
12 @li mp_assertscope.sas
13 @li mddl_dc_filterdetail.sas
14 @li mddl_dc_filtersummary.sas
15 @li mddl_dc_locktable.sas
16 @li mddl_dc_maxkeytable.sas
17 @li mp_filterstore.sas
18
19**/
20
21libname permlib (work);
22
23%mddl_dc_locktable(libds=permlib.locktable)
24%mddl_dc_filtersummary(libds=permlib.filtsum)
25%mddl_dc_filterdetail(libds=permlib.filtdet)
26%mddl_dc_maxkeytable(libds=permlib.maxkey)
27
28data work.class;
29 set sashelp.class;
30run;
31
32/* a view that adds a computed column */
33data work.vw_class / view=work.vw_class;
34 set work.class;
35 length band $8;
36 if age>13 then band='TEEN';
37 else band='JUNIOR';
38run;
39
40/* valid filter - references the computed column */
41data work.inds;
42 infile datalines4 dsd;
43 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
44 OPERATOR_NM:$12. RAW_VALUE:$4000.;
45datalines4;
46AND,AND,1,BAND,=,"'TEEN'"
47AND,AND,1,SEX,=,"'M'"
48;;;;
49run;
50
51%mp_assertscope(SNAPSHOT)
52%mp_filterstore(libds=work.class,
53 targetds=work.vw_class,
54 queryds=work.inds,
55 filter_summary=permlib.filtsum,
56 filter_detail=permlib.filtdet,
57 lock_table=permlib.locktable,
58 maxkeytable=permlib.maxkey,
59 outresult=work.result,
60 outquery=work.query,
61 mdebug=1
62)
63%mp_assertscope(COMPARE)
64
65%mp_assert(iftrue=(&syscc=0),
66 desc=Ensure macro runs without errors,
67 outds=work.test_results
68)
69/* ensure only one record created */
70%mp_assertdsobs(permlib.filtsum,
71 desc=Initial query creates exactly one summary record,
72 test=EQUALS 1,
73 outds=work.test_results
74)
75/* the filter must still be stored against the physical table */
76data work.chk;
77 set permlib.filtsum;
78 where filter_table='WORK.CLASS';
79run;
80%mp_assertdsobs(work.chk,
81 desc=Filter table is the physical table, not the validation target,
82 test=EQUALS 1,
83 outds=work.test_results
84)