Loading...
Searching...
No Matches
mpe_validations_postedit.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Post Edit Hook script for the MPE_VALIDATIONS table
4 @details Post edit hooks provide additional backend validation for user
5 provided data. The incoming dataset is named `work.staging_ds` and is
6 provided in mpe_loader.sas.
7
8 Available macro variables:
9 @li DC_LIBREF - The DC control library
10 @li LIBREF - The library of the dataset being edited (is assigned)
11 @li DS - The dataset being edited
12
13 This validation checks the incoming mpe_validations settings to ensure
14 there are no columns that have both HARDSELECT_HOOK and SOFTSELECT_HOOK.
15
16 <h4> SAS Macros </h4>
17 @li mf_nobs.sas
18
19 <h4> Related Macros </h4>
20 @li mpe_loader.sas
21
22 Hook scripts run inside the service that includes them, so the macros
23 they call are already in that session. They are listed as ignored rather
24 than declared, so the script keeps no macro list of its own to maintain.
25
26 @sasjslint {"ignoredMacros": ["mp_abort"]}
27
28**/
29
30
31/** check to avoid a colum having both HARDSELECT_HOOK and SOFTSELECT_HOOK */
32/* need to merge with base table in the case of a single row being added */
33%global src_list1 src_list2;
34%let src_list1='';
35proc sql noprint;
36create table work.check1 as
37 select quote(catx('.',base_lib,base_ds,base_col)) as source
38 ,rule_type
39 from work.staging_ds
40 where rule_type in ('SOFTSELECT_HOOK','HARDSELECT_HOOK')
41 and upcase(_____DELETE__THIS__RECORD_____) ne "YES";
42
43select distinct cats(source) into: src_list1 separated by ','
44 from work.check1;
45
46create table work.check2 as
47 select quote(catx('.',base_lib,base_ds,base_col)) as source
48 ,rule_type
49 from &DC_LIBREF..MPE_VALIDATIONS
50 where rule_type in ('SOFTSELECT_HOOK','HARDSELECT_HOOK')
51 and &dc_dttmtfmt. lt tx_to
52 and catx('.',base_lib,base_ds,base_col) in (&src_list1);
53
54create table work.check3 as
55 select * from work.check1
56union
57 select * from work.check2;
58
59create table work.validation_checker as
60 select source
61 ,count(*) as cnt
62 from work.check3
63 group by 1
64 having cnt>1;
65
66select distinct source into: src_list2 from work.validation_checker;
67
68data _null_;
69 set work.validation_checker;
70 putlog (_all_)(=);
71run;
72
73
74%mp_abort(iftrue= (%mf_nobs(work.validation_checker)>0)
75 ,mac=mpe_validations_postedit
76 ,msg=%str(The following vars have duplicate HOOKS: &src_list2)
77)
78
79
80/** check that any supplied HARDREGEX / SOFTREGEX rules contain a valid
81 regex pattern. The frontend evaluates these as JavaScript regexes
82 (invalid ones are silently ignored there), so prxparse is used here as
83 a best-effort syntax check to catch typos at config time.
84 An empty pattern is treated as valid (matches everything in JS). */
85data work.regex_check;
86 length source $74;
87 set work.staging_ds(
88 where=(rule_type in ('HARDREGEX','SOFTREGEX')
89 and upcase(_____DELETE__THIS__RECORD_____) ne "YES")
90 );
91 keep source rule_value;
92 if rule_value ne ' ' then do;
93 rx=prxparse(strip(rule_value));
94 if missing(rx) then do;
95 source=catx('.',base_lib,base_ds,base_col);
96 output;
97 end;
98 else call prxfree(rx);
99 end;
100run;
101
102%global src_list3;
103%let src_list3='';
104proc sql noprint;
105select distinct quote(cats(source)) into: src_list3 separated by ','
106 from work.regex_check;
107quit;
108
109%mp_abort(iftrue= (%mf_nobs(work.regex_check)>0)
110 ,mac=mpe_validations_postedit
111 ,msg=%str(The following vars have invalid REGEX patterns: &src_list3)
112)
113