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