Loading...
Searching...
No Matches
mpe_xlmap_info_postedit.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Post Edit Hook script for the MPE_XLMAP_INFO 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 <h4> SAS Macros </h4>
14 @li mf_existds.sas
15 @li mf_getvarlist.sas
16 @li mf_wordsinstr1butnotstr2.sas
17 @li dc_assignlib.sas
18 @li mp_validatecol.sas
19
20 Hook scripts run inside the service that includes them, so the macros
21 they call are already in that session. They are listed as ignored rather
22 than declared, so the script keeps no macro list of its own to maintain.
23
24 @sasjslint {"ignoredMacros": ["mp_abort"]}
25
26**/
27
28data work.staging_ds;
29 set work.staging_ds;
30
31 /* apply the first excel map to all cells */
32 length tgtds $41;
33 retain tgtds;
34 drop tgtds is_libds;
35 if _n_=1 then do;
36 if missing(XLMAP_TARGETLIBDS) then tgtds="&dc_libref..MPE_XLMAP_DATA";
37 else tgtds=upcase(XLMAP_TARGETLIBDS);
38 %mp_validatecol(XLMAP_TARGETLIBDS,LIBDS,is_libds)
39 call symputx('tgtds',tgtds);
40 call symputx('is_libds',is_libds);
41 end;
42 XLMAP_TARGETLIBDS=tgtds;
43
44run;
45
46%mp_abort(iftrue=(&is_libds ne 1)
47 ,mac=mpe_xlmap_info_postedit
48 ,msg=Invalid target dataset (&tgtds)
49)
50
51/**
52 * make sure that the supplied target dataset exists and
53 * has the necessary columns
54 */
55%dc_assignlib(READ,%scan(&tgtds,1,.))
56
57%mp_abort(iftrue=(%mf_existds(libds=&tgtds) ne 1)
58 ,mac=mpe_xlmap_info_postedit
59 ,msg=Target dataset (&tgtds) could not be opened
60)
61
62%let tgtvars=%upcase(%mf_getvarlist(&tgtds));
63%let srcvars=%upcase(%mf_getvarlist(&dc_libref..MPE_XLMAP_DATA));
64%let badvars1=%mf_wordsInStr1ButNotStr2(Str1=&srcvars,Str2=&tgtvars);
65%let badvars2=%mf_wordsInStr1ButNotStr2(Str1=&tgtvars,Str2=&srcvars);
66
67%mp_abort(iftrue=(%length(&badvars1.X)>1)
68 ,mac=mpe_xlmap_info_postedit
69 ,msg=%str(Target dataset (&tgtds) has missing vars: &badvars1)
70)
71
72%mp_abort(iftrue=(%length(&badvars2.X)>1)
73 ,mac=mpe_xlmap_info_postedit
74 ,msg=%str(Target dataset (&tgtds) has unrecognised vars: &badvars2)
75)