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**/
23
24
25/** check to avoid a colum having both HARDSELECT_HOOK and SOFTSELECT_HOOK */
26/* need to merge with base table in the case of a single row being added */
27%global src_list1 src_list2;
28%let src_list1='';
29proc sql noprint;
30create table work.check1 as
31 select quote(catx('.',base_lib,base_ds,base_col)) as source
32 ,rule_type
33 from work.staging_ds
34 where rule_type in ('SOFTSELECT_HOOK','HARDSELECT_HOOK')
35 and upcase(_____DELETE__THIS__RECORD_____) ne "YES";
36
37select distinct cats(source) into: src_list1 separated by ','
38 from work.check1;
39
40create table work.check2 as
41 select quote(catx('.',base_lib,base_ds,base_col)) as source
42 ,rule_type
43 from &DC_LIBREF..MPE_VALIDATIONS
44 where rule_type in ('SOFTSELECT_HOOK','HARDSELECT_HOOK')
45 and &dc_dttmtfmt. lt tx_to
46 and catx('.',base_lib,base_ds,base_col) in (&src_list1);
47
48create table work.check3 as
49 select * from work.check1
50union
51 select * from work.check2;
52
53create table work.validation_checker as
54 select source
55 ,count(*) as cnt
56 from work.check3
57 group by 1
58 having cnt>1;
59
60select distinct source into: src_list2 from work.validation_checker;
61
62data _null_;
63 set work.validation_checker;
64 putlog (_all_)(=);
65run;
66
67
68%mp_abort(iftrue= (%mf_nobs(work.validation_checker)>0)
69 ,mac=mpe_validations_postedit
70 ,msg=%str(The following vars have duplicate HOOKS: &src_list2)
71)
72
73
74/** check that any supplied HARDREGEX / SOFTREGEX rules contain a valid
75 regex pattern. The frontend evaluates these as JavaScript regexes
76 (invalid ones are silently ignored there), so prxparse is used here as
77 a best-effort syntax check to catch typos at config time.
78 An empty pattern is treated as valid (matches everything in JS). */
79data work.regex_check;
80 length source $74;
81 set work.staging_ds(
82 where=(rule_type in ('HARDREGEX','SOFTREGEX')
83 and upcase(_____DELETE__THIS__RECORD_____) ne "YES")
84 );
85 keep source rule_value;
86 if rule_value ne ' ' then do;
87 rx=prxparse(strip(rule_value));
88 if missing(rx) then do;
89 source=catx('.',base_lib,base_ds,base_col);
90 output;
91 end;
92 else call prxfree(rx);
93 end;
94run;
95
96%global src_list3;
97%let src_list3='';
98proc sql noprint;
99select distinct quote(cats(source)) into: src_list3 separated by ','
100 from work.regex_check;
101quit;
102
103%mp_abort(iftrue= (%mf_nobs(work.regex_check)>0)
104 ,mac=mpe_validations_postedit
105 ,msg=%str(The following vars have invalid REGEX patterns: &src_list3)
106)
107