Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_filtervalidate.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Checks a generated filter query for validity
4 @details Runs a generated filter in proc sql with the validate option.
5 Used in mp_filtercheck.sas in an fcmp container.
6
7 Built to support dynamic filtering in
8 [Data Controller for SAS®](https://datacontroller.io).
9
10 Usage:
11
12 data work.filtertable;
13 infile datalines4 dsd;
14 input GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32.
15 OPERATOR_NM:$10. RAW_VALUE:$4000.;
16 datalines4;
17 AND,AND,1,AGE,=,12
18 AND,AND,1,SEX,<=,"'M'"
19 AND,OR,2,Name,NOT IN,"('Jane','Alfred')"
20 AND,OR,2,Weight,>=,7
21 ;;;;
22 run;
23
24 %mp_filtergenerate(work.filtertable,outref=myfilter)
25
26 %mp_filtervalidate(myfilter,sashelp.class)
27
28
29 @returns The SYSCC value will be 1008 if there are validation issues.
30
31 @param [in] inref The input fileref to validate (generated by
32 mp_filtergenerate.sas)
33 @param [in] targetds The target dataset against which to verify the query
34 @param [out] abort= (YES) If YES will call mp_abort.sas on any exceptions
35 @param [out] outds= (work.mp_filtervalidate) Output dataset containing the
36 err / warning message, if one exists. If this table contains any rows,
37 there are problems!
38
39 <h4> SAS Macros </h4>
40 @li mf_getuniquefileref.sas
41 @li mf_nobs.sas
42 @li mp_abort.sas
43
44 <h4> Related Macros </h4>
45 @li mp_filtercheck.sas
46 @li mp_filtergenerate.sas
47
48 @version 9.3
49 @author Allan Bowe
50
51**/
52
53%macro mp_filtervalidate(inref,targetds,abort=YES,outds=work.mp_filtervalidate);
54
55%mp_abort(iftrue= (&syscc ne 0 or &syserr ne 0)
56 ,mac=&sysmacroname
57 ,msg=%str(syscc=&syscc / syserr=&syserr - on macro entry)
58)
59
60%local fref1;
61%let fref1=%mf_getuniquefileref();
62
63data _null_;
64 file &fref1;
65 infile &inref end=eof;
66 if _n_=1 then do;
67 put "proc sql;";
68 put "validate select * from &targetds";
69 put "where " ;
70 end;
71 input;
72 put _infile_;
73 putlog _infile_;
74 if eof then put ";quit;";
75run;
76
77%inc &fref1;
78
79data &outds;
80 if &sqlrc or &syscc or &syserr then do;
81 REASON_CD='VALIDATION_ERR'!!'OR: '!!
82 coalescec(symget('SYSERRORTEXT'),symget('SYSWARNINGTEXT'));
83 output;
84 end;
85 else stop;
86run;
87
88filename &fref1 clear;
89
90%if %mf_nobs(&outds)>0 %then %do;
91 %if &abort=YES %then %do;
92 data _null_;
93 set &outds;
94 call symputx('REASON_CD',reason_cd,'l');
95 stop;
96 run;
97 %mp_abort(
98 mac=&sysmacroname,
99 msg=%str(Filter validation issues.)
100 )
101 %end;
102 %let syscc=1008;
103%end;
104
105%mend mp_filtervalidate;