Loading...
Searching...
No Matches
exportconfig.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Downloads zip file of DC customer configurations
4 @details Zip contains several excel files, containing the customer specific
5 (non-DC) configurations. Useful when migrating to a new instance of
6 Data Controller.
7
8
9 <h4> SAS Macros </h4>
10 @li mf_getuser.sas
11 @li mf_nobs.sas
12 @li mp_abort.sas
13 @li mp_ds2csv.sas
14 @li mp_streamfile.sas
15 @li mp_validatecol.sas
16 @li mpe_getgroups.sas
17
18 @author 4GL Apps Ltd
19 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
20 and may not be re-distributed or re-sold without the express permission of
21 4GL Apps Ltd.
22
23**/
24
25%global dclib islib newlib;
26%mpeinit()
27
28/* check user is in admin group */
29%let cnt=0;
30%mpe_getgroups(user=%mf_getuser(),outds=work.usergroups)
31proc sql noprint;
32select count(*) into:cnt
33 from usergroups
34 where groupname="&mpeadmins";
35%mp_abort(iftrue= (&cnt=0)
36 ,mac=&_program
37 ,msg=%str(The DC configuration can only be exported by &mpeadmins members)
38)
39
40data _null_;
41 newlib=coalescec(symget('dclib'),"&mpelib");
42 %mp_validatecol(newlib,ISLIB,islib)
43 call symputx('islib',islib);
44 call symputx('newlib',upcase(newlib));
45 putlog (_all_)(=);
46run;
47
48%mp_abort(iftrue= (&islib ne 1)
49 ,mac=&_program
50 ,msg=%nrstr(&newlib is not a valid libref)
51)
52
53%let work=%sysfunc(pathname(work));
54%let mime=application/csv;
55%let dbms=CSV;
56%let ext=csv;
57
58%macro conditional_export(ds);
59%if %mf_nobs(&ds)>0 %then %do;
60 /* cannot use PROC EXPORT as we need to wrap all csv char values in quotes */
61 /* cannot use excel as it does not work consistently in all SAS envs */
62 %mp_ds2csv(&ds,outfile="&work/&newlib..&ds..csv",headerformat=NAME)
63 ods package(ProdOutput) add file="&work/&newlib..&ds..&ext" mimetype="&mime";
64%end;
65%mp_abort(iftrue= (&syscc ne 0)
66 ,mac=&_program
67 ,msg=%nrstr(syscc=&syscc after &ds prep)
68)
69%mend conditional_export;
70
71
72ods package(ProdOutput) open nopf;
73
74data MPE_ALERTS;
75 set &mpelib..MPE_ALERTS;
76 where &dc_dttmtfmt. le tx_to;
77 drop tx_: ;
78 if alert_lib="&mpelib" then alert_lib="&newlib";
79run;
80%conditional_export(MPE_ALERTS)
81
82
83data MPE_COLUMN_LEVEL_SECURITY;
84 set &mpelib..MPE_COLUMN_LEVEL_SECURITY;
85 where &dc_dttmtfmt. le tx_to;
86 where also CLS_LIBREF ne "&mpelib";
87 drop tx_: ;
88 CLS_LIBREF="&newlib";
89run;
90%conditional_export(MPE_COLUMN_LEVEL_SECURITY)
91
92data MPE_CONFIG;
93 set &mpelib..MPE_CONFIG;
94 where &dc_dttmtfmt. le tx_to;
95 drop tx_: ;
96 if var_name='DC_MACROS' then var_value=tranwrd(var_value,"&mpelib","&newlib");
97run;
98%conditional_export(MPE_CONFIG)
99
100data MPE_DATADICTIONARY;
101 set &mpelib..MPE_DATADICTIONARY;
102 where &dc_dttmtfmt. le tx_to;
103 drop tx_: ;
104 if DD_SOURCE=:"&mpelib" then do;
105 /* nothing */
106 end;
107 else output;
108run;
109%conditional_export(MPE_DATADICTIONARY)
110
111data MPE_EMAILS;
112 set &mpelib..MPE_EMAILS;
113 where &dc_dttmtfmt. le tx_to;
114 drop tx_: ;
115run;
116%conditional_export(MPE_EMAILS)
117
118data MPE_EXCEL_CONFIG;
119 set &mpelib..MPE_EXCEL_CONFIG;
120 where &dc_dttmtfmt. le tx_to;
121 drop tx_: ;
122 if xl_libref="&mpelib" then xl_libref="&newlib";
123run;
124%conditional_export(MPE_EXCEL_CONFIG)
125
126data MPE_GROUPS;
127 set &mpelib..MPE_GROUPS;
128 where &dc_dttmtfmt. le tx_to;
129 drop tx_: ;
130run;
131%conditional_export(MPE_GROUPS)
132
133data MPE_ROW_LEVEL_SECURITY;
134 set &mpelib..MPE_ROW_LEVEL_SECURITY;
135 where &dc_dttmtfmt. le tx_to;
136 drop tx_: ;
137 if rls_libref="&mpelib" then rls_libref="&newlib";
138run;
139%conditional_export(MPE_ROW_LEVEL_SECURITY)
140
141
142data MPE_SECURITY;
143 set &mpelib..MPE_SECURITY;
144 where &dc_dttmtfmt. le TX_TO;
145 drop tx_: ;
146 if libref="&mpelib" then libref="&newlib";
147run;
148%conditional_export(MPE_SECURITY)
149
150data MPE_SELECTBOX;
151 set &mpelib..MPE_SELECTBOX;
152 where &dc_dttmtfmt. le ver_to_dttm;
153 where also select_lib ne "&mpelib";
154 drop ver_: selectbox_rk;
155run;
156%conditional_export(MPE_SELECTBOX)
157
158data MPE_TABLES;
159 set &mpelib..MPE_TABLES;
160 where &dc_dttmtfmt. le TX_TO;
161 where also LIBREF ne "&mpelib";
162 drop tx_: ;
163run;
164%conditional_export(MPE_TABLES)
165
166data MPE_VALIDATIONS;
167 set &mpelib..MPE_VALIDATIONS;
168 where &dc_dttmtfmt. le TX_TO;
169 where also BASE_LIB ne "&mpelib";
170 drop tx_: ;
171run;
172%conditional_export(MPE_VALIDATIONS)
173
174data MPE_XLMAP_INFO;
175 set &mpelib..MPE_XLMAP_INFO;
176 where &dc_dttmtfmt. le TX_TO;
177 drop tx_: ;
178 if XLMAP_TARGETLIBDS=:"&mpelib.." then
179 XLMAP_TARGETLIBDS=tranwrd(XLMAP_TARGETLIBDS,"&mpelib..","&newlib..");
180run;
181%conditional_export(MPE_XLMAP_INFO)
182
183data MPE_XLMAP_RULES;
184 set &mpelib..MPE_XLMAP_RULES;
185 where &dc_dttmtfmt. le TX_TO;
186 drop tx_: ;
187run;
188%conditional_export(MPE_XLMAP_RULES)
189
190
191/* finish up zip file */
192ods package(ProdOutput) publish archive properties
193 (archive_name="DCBACKUP.zip" archive_path="&work");
194ods package(ProdOutput) close;
195
196%mp_abort(iftrue= (&syscc ne 0)
197 ,mac=&_program..sas
198 ,msg=%nrstr(syscc=&syscc after zip prep)
199)
200
201/* now serve zip file to client */
202%mp_streamfile(contenttype=ZIP
203 ,inloc=%str(&work/DCBACKUP.zip)
204 ,outname=DCBACKUP.zip
205)