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 **/
21 
22 data work.staging_ds;
23  set work.staging_ds;
24 
25  /* apply the first excel map to all cells */
26  length tgtds $41;
27  retain tgtds;
28  drop tgtds is_libds;
29  if _n_=1 then do;
30  if missing(XLMAP_TARGETLIBDS) then tgtds="&dc_libref..MPE_XLMAP_DATA";
31  else tgtds=upcase(XLMAP_TARGETLIBDS);
32  %mp_validatecol(XLMAP_TARGETLIBDS,LIBDS,is_libds)
33  call symputx('tgtds',tgtds);
34  call symputx('is_libds',is_libds);
35  end;
36  XLMAP_TARGETLIBDS=tgtds;
37 
38 run;
39 
40 %mp_abort(iftrue=(&is_libds ne 1)
41  ,mac=mpe_xlmap_info_postedit
42  ,msg=Invalid target dataset (&tgtds)
43 )
44 
45 /**
46  * make sure that the supplied target dataset exists and
47  * has the necessary columns
48  */
49 %dc_assignlib(READ,%scan(&tgtds,1,.))
50 
51 %mp_abort(iftrue=(%mf_existds(libds=&tgtds) ne 1)
52  ,mac=mpe_xlmap_info_postedit
53  ,msg=Target dataset (&tgtds) could not be opened
54 )
55 
56 %let tgtvars=%upcase(%mf_getvarlist(&tgtds));
57 %let srcvars=%upcase(%mf_getvarlist(&dc_libref..MPE_XLMAP_DATA));
58 %let badvars1=%mf_wordsInStr1ButNotStr2(Str1=&srcvars,Str2=&tgtvars);
59 %let badvars2=%mf_wordsInStr1ButNotStr2(Str1=&tgtvars,Str2=&srcvars);
60 
61 %mp_abort(iftrue=(%length(&badvars1.X)>1)
62  ,mac=mpe_xlmap_info_postedit
63  ,msg=%str(Target dataset (&tgtds) has missing vars: &badvars1)
64 )
65 
66 %mp_abort(iftrue=(%length(&badvars2.X)>1)
67  ,mac=mpe_xlmap_info_postedit
68  ,msg=%str(Target dataset (&tgtds) has unrecognised vars: &badvars2)
69 )