Loading...
Searching...
No Matches
validatefilter.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Validates a filter clause before it gets hashified, returns the RK
4 @details Used to generate a FILTER_RK from an input query dataset.
5 Raw values are stored in dc.mpe_filtersource and the meta values are stored
6 in dc.mpe_filteranytable
7
8 <h4> Service Inputs </h4>
9 <h5> IWANT </h5>
10 |FILTER_TABLE:$41.|
11 |---|
12 |DC258467.MPE_X_TEST|
13
14 <h5> FILTERQUERY </h5>
15 |GROUP_LOGIC:$3|SUBGROUP_LOGIC:$3|SUBGROUP_ID:8.|VARIABLE_NM:$32|OPERATOR_NM:$10|RAW_VALUE:$32767|
16 |---|---|---|---|---|---|
17 |AND|AND|1|SOME_BESTNUM|>|1|
18 |AND|AND|1|SOME_TIME|=|77333|
19
20 <h4> Service Outputs </h4>
21
22 <h5> result </h5>
23 @li FILTER_HASH
24 @li FILTER_RK
25 @li FILTER_TABLE
26
27 <h4> SAS Macros </h4>
28 @li dc_assignlib.sas
29 @li mf_nobs.sas
30 @li mp_abort.sas
31 @li mp_filterstore.sas
32 @li mpe_derived.sas
33 @li mpe_validatecol.sas
34 @li removecolsfromwork.sas
35
36 @version 9.2
37 @author 4GL Apps Ltd
38 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
39 and may not be re-distributed or re-sold without the express permission of
40 4GL Apps Ltd.
41
42 @sasjslint {"maxLineLength": 100}
43
44**/
45
46%mpeinit()
47
48/**
49 * filter_table is a request input that flows into executable positions
50 * (mp_filterstore libds=, which interpolates it into SQL). It is read
51 * from the IWANT table in a data step (never re-resolved) and validated
52 * before use - mf_getvalue would re-resolve any macro content in the
53 * value before this code ran. A format catalog is referenced as
54 * LIBREF.CATALOGNAME-FC, so that form is accepted too.
55 */
56%let ds=;
57%let is_libds=0;
58data _null_;
59 length _ds $64;
60 set work.iwant;
61 _ds=filter_table;
62 %mpe_validatecol(_ds,LIBDS,is_libds)
63 if is_libds=0 then putlog 'ERR' 'OR: Invalid filter_table:' _ds;
64 call symputx('is_libds',is_libds,'l');
65 if is_libds=1 then call symputx('ds',upcase(_ds),'l');
66 stop;
67run;
68
69%mp_abort(iftrue= (&is_libds ne 1)
70 ,mac=&_program..sas
71 ,msg=%str(Invalid filter_table)
72)
73
74%dc_assignlib(WRITE,%scan(&ds,1,.))
75
76/* derived variables exist only in a view, so validate against that */
77%mpe_derived(libds=&ds,
78 dclib=&dc_libref,
79 outref=dercode,
80 outview=work.vw_derived,
81 outvars=work.derived_vars
82)
83/* A format catalog (LIBREF.CATALOGNAME-FC) must be left for mp_filterstore to
84 rewrite into a cntlout dataset, and a -FC name handed over as targetds is not
85 something it can read - so pass no targetds at all in that case. An empty
86 targetds makes the engine fall back to libds, which is what a plain dataset
87 wants anyway.
88
89 No macro triggers in this comment: the macro processor resolves them even
90 inside a comment, so prose about conditions is itself executed and the parser
91 reports "Expected DO not found" from here. Same reason the values below are
92 plain LET statements with no trailing comma. */
93%let derived_nobs=%sysfunc(coalesce(%mf_nobs(work.derived_vars),0));
94%let is_fmtcat=%eval(%length(&ds)>3 and "%upcase(%substr(&ds,%length(&ds)-2,3))"="-FC");
95%let targetds_val=&ds;
96/* the derived view keeps precedence: a catalog is only blanked when there is no
97 derived configuration to validate against. Resolved in a data step so the
98 result is written to the global symbol table rather than to a local one. */
99data _null_;
100 if &derived_nobs>0 then call symputx('targetds_val','work.vw_derived');
101 else if &is_fmtcat=1 then call symputx('targetds_val','');
102run;
103
104%mp_filterstore(
105 libds=&ds
106 ,targetds=&targetds_val
107 ,queryds=work.filterquery,
108 filter_summary=&dc_libref..mpe_filteranytable,
109 filter_detail=&dc_libref..mpe_filtersource,
110 lock_table=&dc_libref..mpe_lockanytable,
111 maxkeytable=&dc_libref..mpe_maxkeyvalues,
112 outresult=work.result,
113 outquery=work.query, /* not used */
114 mdebug=1
115)
116
117%removecolsfromwork(___TMP___MD5)
118
119proc sql;
120alter table work.result drop PROCESSED_DTTM;
121
122%webout(OPEN)
123%webout(OBJ,result)
124%webout(CLOSE)
125
126%mpeterm()