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_mkdir.sas
9  @li mf_trimstr.sas
10  @li mp_abort.sas
11  @li mpe_getvars.sas
12  @li mpe_makedata.sas
13  @li mpe_makedatamodel.sas
14  @li mpe_makesampledata.sas
15  @li mv_deletejes.sas
16 
17  @version 3.5
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 
26 %global dcpath ADMIN ;
27 
28 %webout(FETCH)
29 
30 /* enable vars to be passed as url params */
31 %let exist=%sysfunc(exist(work.fromjs));
32 %let inds=%sysfunc(ifc(&exist=1,fromjs,_null_));
33 data _null_;
34  set &inds;
35  call symputx('dcpath',dcpath);
36  call symputx('ADMIN',ADMIN);
37 run;
38 
39 
40 options noquotelenmax;
41 
42 %let dclib=%upcase(VIYA%substr(%sysevalf(%sysfunc(datetime())/60),3,4));
43 %let dclibname=Data Controller (&dclib);
44 %let DC_LIBREF=&dclib;
45 %let work=%sysfunc(pathname(work));
46 
47 
48 %let dcpath=%mf_trimstr(&dcpath,/)/&dclib;
49 %put &=sysuserid;
50 %put &=dcpath;
51 %put &=admin;
52 
53 %mf_mkdir(&dcpath)
54 %mp_abort(iftrue= (&syscc ne 0)
55  ,mac=&_program
56  ,msg=%str(Unable to create &dcpath using &sysuserid)
57 )
58 %mf_mkdir(&dcpath/secret)
59 %mf_mkdir(&dcpath/dc_staging)
60 
61 /* check we have physical permissions to the DCLIB folder */
62 data _null_;
63  putlog "dcpath=&dcpath/permTest.txt";
64  putlog "sysuserid=&sysuserid";
65 data _null_;
66  file "&dcpath/permTest.txt";
67 run;
68 %mp_abort(iftrue= (&syscc ne 0)
69  ,mac=&_program
70  ,msg=%str(User &sysuserid does not have WRITE permissions to: &dcpath )
71 )
72 filename delfile "&dcpath/permTest.txt";
73 data _null_;
74  rc=fdelete('delfile');
75 run;
76 %mp_abort(iftrue= (&syscc ne 0)
77  ,mac=&_program..sas
78  ,msg=%str(User &sysuserid could create (but not delete) &dcpath/permTest.txt )
79 )
80 
81 
82 libname &dclib "&dcpath";
83 %global admin;
84 %let admin=%sysfunc(coalescec(&admin,All Users));
85 %mpe_makedatamodel(lib=&dclib)
86 %mpe_makedata(lib=&dclib,mpeadmins=&admin,path=%str(&dcpath))
87 
88 %mp_abort(iftrue=(&syscc ne 0)
89  ,mac=&sysmacroname
90  ,msg=%str(Err during &dclib build)
91 )
92 
93 
94 /* sample data library */
95 %mf_mkdir(&dcpath/dc_demo)
96 libname dcdemo "&dcpath/dc_demo";
97 %mpe_makesampledata(outlib=DCDEMO)
98 
99 %mp_abort(iftrue=(&syscc ne 0)
100  ,mac=&sysmacroname
101  ,msg=%str(Err during demo data build)
102 )
103 
104 
105 /* the DC precode is stored in the root of the project */
106 %let root=%mf_getapploc(&_program)/services;
107 %put &=root;
108 
109 filename jobout filesrvc folderpath="&root";
110 data _null_;
111  file jobout('settings.sas');
112  put '/* these values are ignored if DC_LIBREF was declared in autoexec */';
113  put ' ';
114  put '%global DC_LIBREF dc_admin_group dc_staging_area ;';
115  put '/* This library (libref) contains the control datasets for DC */';
116  put '/* If a different libref must be used, configure it below */';
117  put '%let DC_LIBREF=' "&dclib;";
118  put ' ';
119  put "libname &dclib '&dcpath' ;";
120  put ' ';
121  put '/* This group has unrestricted access to Data Controller */';
122  put '%let dc_admin_group=' "&admin;";
123  put ' ';
124  put '/* This physical location is used for staging data and audit history */';
125  put '%let dc_staging_area=' "&dcpath/dc_staging;";
126  put ' ';
127  if &syssite in (70221618,70253615) then do;
128  put "libname dcdemo '&dcpath/dc_demo';";
129  end;
130 run;
131 
132 
133 /* create demo data
134 
135 cas dcsession;
136 caslib _all_ assign;
137 caslib casmusic path='/opt/sas/viya/cascache/tracks' libref=casmusic GLOBAL;
138 
139 proc casutil;
140  LOAD DATA=dcdemo.cars
141  CASOUT="cars"
142  OUTCASLIB="casmusic" PROMOTE ;
143 run;
144 */
145 
146 /*
147 cas mysess;
148 caslib _all_ assign;
149 data casmusic.artists(promote=yes);
150  length name varchar(30);
151  do tracks=1 to 100;
152  name='Phil Collins'!!cats(tracks);
153  output;
154  end;
155 run;
156 */
157 /*
158 %let url=http://millionsongdataset.com/sites/default/files/AdditionalFiles%trim(
159  )/unique_tracks.txt;
160 filename test url "&url" lrecl=3000 ;
161 
162 proc sql;
163 drop table casmusic.tunes;
164 
165 data tracks;
166  infile test dlmstr='<SEP>' dsd end=lastobs;
167  input track_id:$32. song_id:$32. artist_nm:$128. title:$256.;
168  output;
169  if lastobs then do;
170  track_id='dummyrecords';
171  title='none';
172  artist_nm='none';
173  do x=1 to 4000000;
174  drop x;
175  song_id=cats(x);
176  output;
177  end;
178  stop;
179  end;
180 run;
181 
182 proc casutil;
183  LOAD DATA=tracks
184  CASOUT="tunes"
185  OUTCASLIB="casmusic" PROMOTE ;
186 run;
187 /*
188 data append;
189  if 0 then set &dclib..MPE_TABLES;
190  libref="CASMUSIC";
191  dsn='TUNES';
192  num_of_approvals_required=1;
193  loadtype='UPDATE';
194  buskey='TRACK_ID SONG_ID';
195  tx_from=0;
196  tx_to='31DEC9999:23:59:59'dt;
197  output;
198  dsn='ARTISTS';
199  buskey='NAME';
200  output;
201 run;
202 proc append base=&dclib..MPE_tABLES data=append;
203 run;
204 */
205 %mp_abort(iftrue=(&syscc ne 0)
206  ,mac=&sysmacroname
207  ,msg=%str(Err during settings job creation)
208 )
209 
210 
211 %webout(OPEN)
212 data result;
213  dclib="&dclib";
214  admingroup="&admin";
215  dcpath="&dcpath";
216 run;
217 %webout(OBJ,result)
218 %webout(CLOSE)
219 
220 %mv_deletejes(path=&root/admin, name=makedata)