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