Loading...
Searching...
No Matches
makedata.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief self destructing setup service
4 @details Will create the database and perform config activities
5
6 <h4> SAS Macros </h4>
7 @li mf_getapploc.sas
8 @li mf_getuniquefileref.sas
9 @li mf_mkdir.sas
10 @li mf_trimstr.sas
11 @li mp_abort.sas
12 @li mpe_getvars.sas
13 @li mpe_makedata.sas
14 @li mpe_makedatamodel.sas
15 @li mpe_makesampledata.sas
16 @li mv_createfile.sas
17 @li mv_deletejes.sas
18
19 @version 3.5
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
28%global dcpath ADMIN _contextname ;
29
30%webout(FETCH)
31
32/* enable vars to be passed as url params */
33%let exist=%sysfunc(exist(work.fromjs));
34%let inds=%sysfunc(ifc(&exist=1,fromjs,_null_));
35
36data _null_;
37 set &inds;
38 call symputx('dcpath',dcpath);
39 call symputx('ADMIN',ADMIN);
40 call symputx('_contextname',_contextname);
41run;
42
43
44options noquotelenmax;
45
46%let dclib=%upcase(VIYA%substr(%sysevalf(%sysfunc(datetime())/60),3,4));
47%let dclibname=Data Controller (&dclib);
48%let DC_LIBREF=&dclib;
49%let work=%sysfunc(pathname(work));
50
51
52%let dcpath=%mf_trimstr(&dcpath,/)/&dclib;
53%put &=sysuserid;
54%put &=dcpath;
55%put &=admin;
56
57%mf_mkdir(&dcpath)
58%mp_abort(iftrue= (&syscc ne 0)
59 ,mac=&_program
60 ,msg=%str(Unable to create &dcpath using &sysuserid)
61)
62%mf_mkdir(&dcpath/secret)
63%mf_mkdir(&dcpath/dc_staging)
64
65/* check we have physical permissions to the DCLIB folder */
66data _null_;
67 putlog "dcpath=&dcpath/permTest.txt";
68 putlog "sysuserid=&sysuserid";
69data _null_;
70 file "&dcpath/permTest.txt";
71run;
72%mp_abort(iftrue= (&syscc ne 0)
73 ,mac=&_program
74 ,msg=%str(User &sysuserid does not have WRITE permissions to: &dcpath )
75)
76filename delfile "&dcpath/permTest.txt";
77data _null_;
78 rc=fdelete('delfile');
79run;
80%mp_abort(iftrue= (&syscc ne 0)
81 ,mac=&_program..sas
82 ,msg=%str(User &sysuserid could create (but not delete) &dcpath/permTest.txt )
83)
84
85
86libname &dclib "&dcpath";
87%global admin;
88%let admin=%sysfunc(coalescec(&admin,All Users));
89%mpe_makedatamodel(lib=&dclib)
90%mpe_makedata(lib=&dclib,mpeadmins=&admin,path=%str(&dcpath))
91
92%mp_abort(iftrue=(&syscc ne 0)
93 ,mac=&sysmacroname
94 ,msg=%str(Err during &dclib build)
95)
96
97
98/* sample data library */
99%mf_mkdir(&dcpath/dc_demo)
100libname dcdemo "&dcpath/dc_demo";
101%mpe_makesampledata(outlib=DCDEMO)
102
103%mp_abort(iftrue=(&syscc ne 0)
104 ,mac=&sysmacroname
105 ,msg=%str(Err during demo data build)
106)
107
108
109/* the DC precode is stored in the root of the project */
110%let root=%mf_getapploc(&_program)/services;
111%put &=root;
112
113filename jobout filesrvc folderpath="&root";
114data _null_;
115 file jobout('settings.sas');
116 put '/* these values are ignored if DC_LIBREF was declared in autoexec */';
117 put ' ';
118 put '%global DC_LIBREF dc_admin_group dc_staging_area ;';
119 put '/* This library (libref) contains the control datasets for DC */';
120 put '/* If a different libref must be used, configure it below */';
121 put '%let DC_LIBREF=' "&dclib;";
122 put ' ';
123 put "libname &dclib '&dcpath' ;";
124 put ' ';
125 put '/* This group has unrestricted access to Data Controller */';
126 put '%let dc_admin_group=' "&admin;";
127 put ' ';
128 put '/* This physical location is used for staging data and audit history */';
129 put '%let dc_staging_area=' "&dcpath/dc_staging;";
130 put ' ';
131 put 'cas dcsession sessopts=(caslib=casuser);';
132 put 'caslib _all_ assign;';
133 put ' ';
134 if &syssite in (70221618,70253615) then do;
135 put "libname dcdemo '&dcpath/dc_demo';";
136 end;
137run;
138
139
140/* create demo data
141
142cas dcsession;
143caslib _all_ assign;
144caslib casmusic path='/opt/sas/viya/cascache/tracks' libref=casmusic GLOBAL;
145
146proc casutil;
147 LOAD DATA=dcdemo.cars
148 CASOUT="cars"
149 OUTCASLIB="casmusic" PROMOTE ;
150run;
151*/
152
153/*
154cas mysess;
155caslib _all_ assign;
156data casmusic.artists(promote=yes);
157 length name varchar(30);
158 do tracks=1 to 100;
159 name='Phil Collins'!!cats(tracks);
160 output;
161 end;
162run;
163*/
164/*
165%let url=http://millionsongdataset.com/sites/default/files/AdditionalFiles%trim(
166 )/unique_tracks.txt;
167filename test url "&url" lrecl=3000 ;
168
169proc sql;
170drop table casmusic.tunes;
171
172data tracks;
173 infile test dlmstr='<SEP>' dsd end=lastobs;
174 input track_id:$32. song_id:$32. artist_nm:$128. title:$256.;
175 output;
176 if lastobs then do;
177 track_id='dummyrecords';
178 title='none';
179 artist_nm='none';
180 do x=1 to 4000000;
181 drop x;
182 song_id=cats(x);
183 output;
184 end;
185 stop;
186 end;
187run;
188
189proc casutil;
190 LOAD DATA=tracks
191 CASOUT="tunes"
192 OUTCASLIB="casmusic" PROMOTE ;
193run;
194/*
195data append;
196 if 0 then set &dclib..MPE_TABLES;
197 libref="CASMUSIC";
198 dsn='TUNES';
199 num_of_approvals_required=1;
200 loadtype='UPDATE';
201 buskey='TRACK_ID SONG_ID';
202 tx_from=0;
203 tx_to='31DEC9999:23:59:59'dt;
204 output;
205 dsn='ARTISTS';
206 buskey='NAME';
207 output;
208run;
209proc append base=&dclib..MPE_tABLES data=append;
210run;
211*/
212%mp_abort(iftrue=(&syscc ne 0)
213 ,mac=&sysmacroname
214 ,msg=%str(Err during settings job creation)
215)
216
217/* Update the compute context in the streamed frontend (DC.html) so that
218 Data Controller runs under the same context that was selected when this
219 service was invoked. The file must be re-created using %mv_createfile
220 (the same macro used to stream the frontend at deploy time) rather than
221 updated in place with a filesrvc fileref - only the Files service POST
222 assigns the correct mime type (text/html / file_html), without which the
223 frontend will not stream. This service is always invoked from a URL so
224 the _contextname parameter is always present. */
225%global _contextname;
226%let dchtml_in=%mf_getuniquefileref();
227%let dchtml_out=%mf_getuniquefileref();
228
229/* Escape regex metacharacters (\ and $) in the context name so they are
230 treated as literals when embedded in the prxchange replacement string.
231 In a Perl regex replacement, \ introduces a backreference and $ introduces
232 variable interpolation; prefixing each with \ quotes them as literals. */
233data _null_;
234 length _ctxname $256 _ctxesc $512;
235 _ctxname=symget('_contextname');
236 _ctxesc=tranwrd(tranwrd(_ctxname,'\','\\'),'$','\$');
237 call symputx('_contextname_escaped',_ctxesc);
238run;
239
240/* read the existing frontend */
241filename &dchtml_in filesrvc folderpath="&root" filename="DC.html"
242 lrecl=32767;
243%mp_abort(iftrue= (&syscc ne 0)
244 ,mac=&sysmacroname
245 ,msg=%str(Unable to open DC.html in &root)
246)
247
248/* write the updated html to a temporary file */
249data _null_;
250 file &dchtml_out lrecl=32767;
251 infile &dchtml_in lrecl=32767 truncover;
252 input;
253 length line $32767;
254 line=prxchange(cats('s|contextname="[^"]*"|contextname="'
255 ,symget('_contextname_escaped')
256 ,'"|'
257 ),-1,_infile_);
258 put line;
259run;
260filename &dchtml_in clear;
261
262%mp_abort(iftrue= (&syscc ne 0)
263 ,mac=&sysmacroname
264 ,msg=%str(Unable to update compute context in DC.html)
265)
266
267/* re-create DC.html via the Files service to retain the html mime type */
268%mv_createfile(path=&root, name=DC.html, inref=&dchtml_out)
269filename &dchtml_out clear;
270
271
272%webout(OPEN)
273data result;
274 dclib="&dclib";
275 admingroup="&admin";
276 dcpath="&dcpath";
277run;
278%webout(OBJ,result)
279%webout(CLOSE)
280
281%mv_deletejes(path=&root/admin, name=makedata)