mpe_validatefilter.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Validates a filter clause and updates the source tables
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  Input data format:
9 
10  |GROUP_LOGIC:$3|SUBGROUP_LOGIC:$3|SUBGROUP_ID:8.|VARIABLE_NM:$32|OPERATOR_NM:$10|RAW_VALUE:$32767|
11  |---|---|---|---|---|---|
12  |AND|AND|1|SOME_BESTNUM|>|1|
13  |AND|AND|1|SOME_TIME|=|77333|
14 
15 
16  @param [in] libds= The target dataset to be filtered (lib should be assigned)
17  @param [in] queryds= The input query dataset to be validated
18  @param [in] dclib= The control library for Data Controller
19  @param [out] outresult= The result table with the FILTER_RK
20  @param [out] outquery= The original query, taken as extract after table load
21 
22 
23 
24  <h4> SAS Macros </h4>
25  @li bitemporal_dataloader.sas
26  @li mf_getvalue.sas
27  @li mf_nobs.sas
28  @li mp_abort.sas
29  @li mp_filtercheck.sas
30  @li mp_hashdataset.sas
31  @li removecolsfromwork.sas
32 
33  @version 9.2
34  @author 4GL Apps Ltd
35  @copyright 4GL Apps Ltd. This code may only be used within Data Controller
36  and may not be re-distributed or re-sold without the express permission of
37  4GL Apps Ltd.
38 
39 **/
40 
41 %macro mpe_validatefilter(libds=,
42  queryds=work.filterquery,
43  dclib=NOTPROVIDED,
44  outresult=work.result,
45  outquery=work.query
46 );
47 
48 %put &sysmacroname entry vars:;
49 %put _local_;
50 
51 %global _program;
52 
53 %mp_abort(iftrue= (&dclib=NOTPROVIDED)
54  ,mac=&sysmacroname
55  ,msg=%str(dclib=NOTPROVIDED)
56 )
57 
58 %mp_filtercheck(&queryds,targetds=&libds,abort=YES)
59 
60 %mp_hashdataset(&queryds,outds=myhash,salt=&libds)
61 
62 %local filter_hash;
63 %let filter_hash=%upcase(%mf_getvalue(work.myhash,hashkey));
64 
65 %put &=filter_hash;
66 data _null_;
67  set work.myhash;
68  putlog (_all_)(=);
69 run;
70 
71 data &outresult;
72  set &dclib..mpe_filteranytable;
73  where filter_hash="&filter_hash";
74 run;
75 
76 %mp_abort(iftrue= (&syscc ne 0)
77  ,mac=&_program
78  ,msg=%str(syscc=&syscc )
79 )
80 %mp_abort(iftrue= ("&filter_hash"=" ")
81  ,mac=&_program
82  ,msg=%str(problem with filter_hash generation)
83 )
84 
85 %if %mf_nobs(&outresult)=0 %then %do;
86 
87  /* update source table first */
88  data work.filtersource;
89  set &queryds;
90  filter_hash="&filter_hash";
91  filter_line=_n_;
92  run;
93  %bitemporal_dataloader(base_lib=&dclib
94  ,base_dsn=mpe_filtersource
95  ,append_dsn=filtersource
96  ,PK=filter_hash filter_line
97  ,etlsource=&_program
98  ,loadtype=UPDATE
99  ,processed=PROCESSED_DTTM
100  ,dclib=&dclib
101  )
102 
103  data filter1;
104  if 0 then set &dclib..mpe_filteranytable;
105  filter_table=symget('libds');
106  filter_hash="&filter_hash";
107  output;
108  stop;
109  run;
110 
111  %bitemporal_dataloader(base_lib=&dclib
112  ,base_dsn=mpe_filteranytable
113  ,append_dsn=filter1
114  ,PK=filter_rk
115  ,rk_underlying=filter_hash
116  ,etlsource=&_program
117  ,loadtype=UPDATE
118  ,processed=PROCESSED_DTTM
119  ,dclib=&dclib
120  )
121 
122  data &outresult;
123  set &dclib..mpe_filteranytable;
124  where filter_hash="&filter_hash";
125  run;
126 
127  %removecolsfromwork(___TMP___MD5)
128 
129 %end;
130 
131 proc sort data=&dclib..mpe_filtersource(where=(filter_hash="&filter_hash"))
132  out=&outquery(drop=filter_hash filter_line processed_dttm);
133  by filter_line;
134 run;
135 
136 %mend mpe_validatefilter;