@sasjs/core 3.11.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,16 +17,21 @@
17
17
  %inc mc;
18
18
  %mp_guesspk(sashelp.class,outds=classpks)
19
19
 
20
- @param baseds The dataset to analyse
21
- @param outds= The output dataset to contain the possible PKs
22
- @param max_guesses= (3) The total number of possible primary keys to generate.
23
- A table may have multiple unlikely PKs, so no need to list them all.
24
- @param min_rows= (5) The minimum number of rows a table should have in order
25
- to try and guess the PK.
20
+ @param [in] baseds The dataset to analyse
21
+ @param [out] outds= The output dataset to contain the possible PKs
22
+ @param [in] max_guesses= (3) The total number of possible primary keys to
23
+ generate. A table may have multiple (unlikely) PKs, so no need to list them
24
+ all.
25
+ @param [in] min_rows= (5) The minimum number of rows a table should have in
26
+ order to try and guess the PK.
27
+ @param [in] ignore_cols (0) Space seperated list of columns which you are
28
+ sure are not part of the primary key (helps to avoid false positives)
29
+ @param [in] mdebug= Set to 1 to enable DEBUG messages and preserve outputs
26
30
 
27
31
  <h4> SAS Macros </h4>
28
32
  @li mf_getvarlist.sas
29
33
  @li mf_getuniquename.sas
34
+ @li mf_wordsInstr1butnotstr2.sas
30
35
  @li mf_nobs.sas
31
36
 
32
37
  <h4> Related Macros </h4>
@@ -38,179 +43,226 @@
38
43
  **/
39
44
 
40
45
  %macro mp_guesspk(baseds
41
- ,outds=mp_guesspk
42
- ,max_guesses=3
43
- ,min_rows=5
46
+ ,outds=mp_guesspk
47
+ ,max_guesses=3
48
+ ,min_rows=5
49
+ ,ignore_cols=0
50
+ ,mdebug=0
44
51
  )/*/STORE SOURCE*/;
45
-
46
- /* declare local vars */
47
- %local var vars vcnt i j k l tmpvar tmpds rows posspks ppkcnt;
48
- %let vars=%mf_getvarlist(&baseds);
49
- %let vcnt=%sysfunc(countw(&vars));
50
-
51
- %if &vcnt=0 %then %do;
52
- %put &sysmacroname: &baseds has no variables! Exiting.;
53
- %return;
54
- %end;
55
-
56
- /* get null count and row count */
57
- %let tmpvar=%mf_getuniquename();
58
- proc sql noprint;
59
- create table _data_ as select
60
- count(*) as &tmpvar
61
- %do i=1 %to &vcnt;
62
- %let var=%scan(&vars,&i);
63
- ,sum(case when &var is missing then 1 else 0 end) as &var
64
- %end;
65
- from &baseds;
66
-
67
- /* transpose table and scan for not null cols */
68
- proc transpose;
69
- data _null_;
70
- set &syslast end=last;
71
- length vars $32767;
72
- retain vars ;
73
- if _name_="&tmpvar" then call symputx('rows',col1,'l');
74
- else if col1=0 then vars=catx(' ',vars,_name_);
75
- if last then call symputx('posspks',vars,'l');
76
- run;
77
-
78
- %let ppkcnt=%sysfunc(countw(&posspks));
79
- %if &ppkcnt=0 %then %do;
80
- %put &sysmacroname: &baseds has no non-missing variables! Exiting.;
81
- %return;
82
- %end;
83
-
84
- proc sort data=&baseds(keep=&posspks) out=_data_ noduprec;
85
- by _all_;
86
- run;
87
- %local pkds; %let pkds=&syslast;
88
-
89
- %if &rows > %mf_nobs(&pkds) %then %do;
90
- %put &sysmacroname: &baseds has no combination of unique records! Exiting.;
91
- %return;
92
- %end;
93
-
94
- /* now check cardinality */
95
- proc sql noprint;
96
- create table _data_ as select
97
- %do i=1 %to &ppkcnt;
98
- %let var=%scan(&posspks,&i);
99
- count(distinct &var) as &var
100
- %if &i<&ppkcnt %then ,;
101
- %end;
102
- from &pkds;
103
-
104
- /* transpose and sort by cardinality */
105
- proc transpose;
106
- proc sort; by descending col1;
107
- run;
108
-
109
- /* create initial PK list and re-order posspks list */
110
- data &outds(keep=pkguesses);
111
- length pkguesses $5000 vars $5000;
112
- set &syslast end=last;
113
- retain vars ;
114
- vars=catx(' ',vars,_name_);
115
- if col1=&rows then do;
116
- pkguesses=_name_;
117
- output;
118
- end;
119
- if last then call symputx('posspks',vars,'l');
120
- run;
121
-
122
- %if %mf_nobs(&outds) ge &max_guesses %then %do;
123
- %put &sysmacroname: %mf_nobs(&outds) possible primary key values found;
124
- %return;
125
- %end;
126
-
127
- %if &ppkcnt=1 %then %do;
128
- %put &sysmacroname: No more PK guess possible;
129
- %return;
52
+ %local dbg;
53
+ %if &mdebug=1 %then %do;
54
+ %put &sysmacroname entry vars:;
55
+ %put _local_;
56
+ %end;
57
+ %else %let dbg=*;
58
+
59
+ /* declare local vars */
60
+ %local var vars vcnt i j k l tmpvar tmpds rows posspks ppkcnt;
61
+ %let vars=%upcase(%mf_getvarlist(&baseds));
62
+ %let vars=%mf_wordsInStr1ButNotStr2(str1=&vars,str2=%upcase(&ignore_cols));
63
+ %let vcnt=%sysfunc(countw(&vars));
64
+
65
+ %if &vcnt=0 %then %do;
66
+ %put &sysmacroname: &baseds has no variables! Exiting.;
67
+ %return;
68
+ %end;
69
+
70
+ /* get null count and row count */
71
+ %let tmpvar=%mf_getuniquename();
72
+ proc sql noprint;
73
+ create table _data_ as select
74
+ count(*) as &tmpvar
75
+ %do i=1 %to &vcnt;
76
+ %let var=%scan(&vars,&i);
77
+ ,sum(case when &var is missing then 1 else 0 end) as &var
78
+ %end;
79
+ from &baseds;
80
+
81
+ /* transpose table and scan for not null cols */
82
+ proc transpose;
83
+ data _null_;
84
+ set &syslast end=last;
85
+ length vars $32767;
86
+ retain vars ;
87
+ if _name_="&tmpvar" then call symputx('rows',col1,'l');
88
+ else if col1=0 then vars=catx(' ',vars,_name_);
89
+ if last then call symputx('posspks',vars,'l');
90
+ run;
91
+
92
+ %let ppkcnt=%sysfunc(countw(&posspks));
93
+ %if &ppkcnt=0 %then %do;
94
+ %put &sysmacroname: &baseds has no non-missing variables! Exiting.;
95
+ %return;
96
+ %end;
97
+
98
+ proc sort data=&baseds(keep=&posspks) out=_data_ noduprec;
99
+ by _all_;
100
+ run;
101
+ %local pkds; %let pkds=&syslast;
102
+
103
+ %if &rows > %mf_nobs(&pkds) %then %do;
104
+ %put &sysmacroname: &baseds has no combination of unique records! Exiting.;
105
+ %return;
106
+ %end;
107
+
108
+ /* now check cardinality */
109
+ proc sql noprint;
110
+ create table _data_ as select
111
+ %do i=1 %to &ppkcnt;
112
+ %let var=%scan(&posspks,&i);
113
+ count(distinct &var) as &var
114
+ %if &i<&ppkcnt %then ,;
115
+ %end;
116
+ from &pkds;
117
+
118
+ /* transpose and sort by cardinality */
119
+ proc transpose;
120
+ proc sort; by descending col1;
121
+ run;
122
+
123
+ /* create initial PK list and re-order posspks list */
124
+ data &outds(keep=pkguesses);
125
+ length pkguesses $5000 vars $5000;
126
+ set &syslast end=last;
127
+ retain vars ;
128
+ vars=catx(' ',vars,_name_);
129
+ if col1=&rows then do;
130
+ pkguesses=_name_;
131
+ output;
132
+ end;
133
+ if last then call symputx('posspks',vars,'l');
134
+ run;
135
+
136
+ %if %mf_nobs(&outds) ge &max_guesses %then %do;
137
+ %put &sysmacroname: %mf_nobs(&outds) possible primary key values found;
138
+ %return;
139
+ %end;
140
+
141
+ %if &ppkcnt=1 %then %do;
142
+ %put &sysmacroname: No more PK guess possible;
143
+ %return;
144
+ %end;
145
+
146
+ /* begin scanning for uniques on pairs of PKs */
147
+ %let tmpds=%mf_getuniquename();
148
+ %local lev1 lev2;
149
+ %do i=1 %to &ppkcnt;
150
+ %let lev1=%scan(&posspks,&i);
151
+ %do j=2 %to &ppkcnt;
152
+ %let lev2=%scan(&posspks,&j);
153
+ %if &lev1 ne &lev2 %then %do;
154
+ /* check for two level uniqueness */
155
+ proc sort data=&pkds(keep=&lev1 &lev2) out=&tmpds noduprec;
156
+ by _all_;
157
+ run;
158
+ %if %mf_nobs(&tmpds)=&rows %then %do;
159
+ proc sql;
160
+ insert into &outds values("&lev1 &lev2");
161
+ %if %mf_nobs(&outds) ge &max_guesses %then %do;
162
+ %put &sysmacroname: Max PKs reached at Level 2 for &baseds;
163
+ %goto exit;
164
+ %end;
165
+ %end;
166
+ %end;
130
167
  %end;
131
-
132
- /* begin scanning for uniques on pairs of PKs */
133
- %let tmpds=%mf_getuniquename();
134
- %local lev1 lev2;
135
- %do i=1 %to &ppkcnt;
136
- %let lev1=%scan(&posspks,&i);
137
- %do j=2 %to &ppkcnt;
138
- %let lev2=%scan(&posspks,&j);
139
- %if &lev1 ne &lev2 %then %do;
140
- /* check for two level uniqueness */
141
- proc sort data=&pkds(keep=&lev1 &lev2) out=&tmpds noduprec;
168
+ %end;
169
+
170
+ %if &ppkcnt=2 %then %do;
171
+ %put &sysmacroname: No more PK guess possible;
172
+ %goto exit;
173
+ %end;
174
+
175
+ /* begin scanning for uniques on PK triplets */
176
+ %local lev3;
177
+ %do i=1 %to &ppkcnt;
178
+ %let lev1=%scan(&posspks,&i);
179
+ %do j=2 %to &ppkcnt;
180
+ %let lev2=%scan(&posspks,&j);
181
+ %if &lev1 ne &lev2 %then %do k=3 %to &ppkcnt;
182
+ %let lev3=%scan(&posspks,&k);
183
+ %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do;
184
+ /* check for three level uniqueness */
185
+ proc sort data=&pkds(keep=&lev1 &lev2 &lev3) out=&tmpds noduprec;
142
186
  by _all_;
143
187
  run;
144
188
  %if %mf_nobs(&tmpds)=&rows %then %do;
145
189
  proc sql;
146
- insert into &outds values("&lev1 &lev2");
190
+ insert into &outds values("&lev1 &lev2 &lev3");
147
191
  %if %mf_nobs(&outds) ge &max_guesses %then %do;
148
- %put &sysmacroname: Max PKs reached at Level 2 for &baseds;
149
- %return;
192
+ %put &sysmacroname: Max PKs reached at Level 3 for &baseds;
193
+ %goto exit;
150
194
  %end;
151
195
  %end;
152
196
  %end;
153
197
  %end;
154
198
  %end;
155
-
156
- %if &ppkcnt=2 %then %do;
157
- %put &sysmacroname: No more PK guess possible;
158
- %return;
159
- %end;
160
-
161
- /* begin scanning for uniques on PK triplets */
162
- %local lev3;
163
- %do i=1 %to &ppkcnt;
164
- %let lev1=%scan(&posspks,&i);
165
- %do j=2 %to &ppkcnt;
166
- %let lev2=%scan(&posspks,&j);
167
- %if &lev1 ne &lev2 %then %do k=3 %to &ppkcnt;
168
- %let lev3=%scan(&posspks,&k);
169
- %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do;
170
- /* check for three level uniqueness */
171
- proc sort data=&pkds(keep=&lev1 &lev2 &lev3) out=&tmpds noduprec;
199
+ %end;
200
+
201
+ %if &ppkcnt=3 %then %do;
202
+ %put &sysmacroname: No more PK guess possible;
203
+ %goto exit;
204
+ %end;
205
+
206
+ /* scan for uniques on up to 4 PK fields */
207
+ %local lev4;
208
+ %do i=1 %to &ppkcnt;
209
+ %let lev1=%scan(&posspks,&i);
210
+ %do j=2 %to &ppkcnt;
211
+ %let lev2=%scan(&posspks,&j);
212
+ %if &lev1 ne &lev2 %then %do k=3 %to &ppkcnt;
213
+ %let lev3=%scan(&posspks,&k);
214
+ %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
215
+ %let lev4=%scan(&posspks,&l);
216
+ %if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then %do;
217
+ /* check for four level uniqueness */
218
+ proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4)
219
+ out=&tmpds noduprec;
172
220
  by _all_;
173
221
  run;
174
222
  %if %mf_nobs(&tmpds)=&rows %then %do;
175
223
  proc sql;
176
- insert into &outds values("&lev1 &lev2 &lev3");
224
+ insert into &outds values("&lev1 &lev2 &lev3 &lev4");
177
225
  %if %mf_nobs(&outds) ge &max_guesses %then %do;
178
- %put &sysmacroname: Max PKs reached at Level 3 for &baseds;
179
- %return;
226
+ %put &sysmacroname: Max PKs reached at Level 4 for &baseds;
227
+ %goto exit;
180
228
  %end;
181
229
  %end;
182
230
  %end;
183
231
  %end;
184
232
  %end;
185
233
  %end;
186
-
187
- %if &ppkcnt=3 %then %do;
188
- %put &sysmacroname: No more PK guess possible;
189
- %return;
190
- %end;
191
-
192
- /* scan for uniques on up to 4 PK fields */
193
- %local lev4;
194
- %do i=1 %to &ppkcnt;
195
- %let lev1=%scan(&posspks,&i);
196
- %do j=2 %to &ppkcnt;
197
- %let lev2=%scan(&posspks,&j);
198
- %if &lev1 ne &lev2 %then %do k=3 %to &ppkcnt;
199
- %let lev3=%scan(&posspks,&k);
200
- %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
201
- %let lev4=%scan(&posspks,&l);
202
- %if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then %do;
234
+ %end;
235
+
236
+ %if &ppkcnt=4 %then %do;
237
+ %put &sysmacroname: No more PK guess possible;
238
+ %goto exit;
239
+ %end;
240
+
241
+ /* scan for uniques on up to 4 PK fields */
242
+ %local lev5 m;
243
+ %do i=1 %to &ppkcnt;
244
+ %let lev1=%scan(&posspks,&i);
245
+ %do j=2 %to &ppkcnt;
246
+ %let lev2=%scan(&posspks,&j);
247
+ %if &lev1 ne &lev2 %then %do k=3 %to &ppkcnt;
248
+ %let lev3=%scan(&posspks,&k);
249
+ %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
250
+ %let lev4=%scan(&posspks,&l);
251
+ %if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
252
+ %do m=5 %to &ppkcnt;
253
+ %let lev5=%scan(&posspks,&m);
254
+ %if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %do;
203
255
  /* check for four level uniqueness */
204
- proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4)
256
+ proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5)
205
257
  out=&tmpds noduprec;
206
258
  by _all_;
207
259
  run;
208
260
  %if %mf_nobs(&tmpds)=&rows %then %do;
209
261
  proc sql;
210
- insert into &outds values("&lev1 &lev2 &lev3 &lev4");
262
+ insert into &outds values("&lev1 &lev2 &lev3 &lev4 &lev5");
211
263
  %if %mf_nobs(&outds) ge &max_guesses %then %do;
212
- %put &sysmacroname: Max PKs reached at Level 4 for &baseds;
213
- %return;
264
+ %put &sysmacroname: Max PKs reached at Level 5 for &baseds;
265
+ %goto exit;
214
266
  %end;
215
267
  %end;
216
268
  %end;
@@ -218,83 +270,44 @@
218
270
  %end;
219
271
  %end;
220
272
  %end;
221
-
222
- %if &ppkcnt=4 %then %do;
223
- %put &sysmacroname: No more PK guess possible;
224
- %return;
225
- %end;
226
-
227
- /* scan for uniques on up to 4 PK fields */
228
- %local lev5 m;
229
- %do i=1 %to &ppkcnt;
230
- %let lev1=%scan(&posspks,&i);
231
- %do j=2 %to &ppkcnt;
232
- %let lev2=%scan(&posspks,&j);
233
- %if &lev1 ne &lev2 %then %do k=3 %to &ppkcnt;
234
- %let lev3=%scan(&posspks,&k);
235
- %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
236
- %let lev4=%scan(&posspks,&l);
237
- %if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
238
- %do m=5 %to &ppkcnt;
239
- %let lev5=%scan(&posspks,&m);
240
- %if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %do;
273
+ %end;
274
+
275
+ %if &ppkcnt=5 %then %do;
276
+ %put &sysmacroname: No more PK guess possible;
277
+ %goto exit;
278
+ %end;
279
+
280
+ /* scan for uniques on up to 4 PK fields */
281
+ %local lev6 n;
282
+ %do i=1 %to &ppkcnt;
283
+ %let lev1=%scan(&posspks,&i);
284
+ %do j=2 %to &ppkcnt;
285
+ %let lev2=%scan(&posspks,&j);
286
+ %if &lev1 ne &lev2 %then %do k=3 %to &ppkcnt;
287
+ %let lev3=%scan(&posspks,&k);
288
+ %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
289
+ %let lev4=%scan(&posspks,&l);
290
+ %if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
291
+ %do m=5 %to &ppkcnt;
292
+ %let lev5=%scan(&posspks,&m);
293
+ %if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5
294
+ %then %do n=6 %to &ppkcnt;
295
+ %let lev6=%scan(&posspks,&n);
296
+ %if &lev1 ne &lev6 & &lev2 ne &lev6 & &lev3 ne &lev6
297
+ & &lev4 ne &lev6 & &lev5 ne &lev6 %then
298
+ %do;
241
299
  /* check for four level uniqueness */
242
- proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5)
243
- out=&tmpds noduprec;
300
+ proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5 &lev6)
301
+ out=&tmpds noduprec;
244
302
  by _all_;
245
303
  run;
246
304
  %if %mf_nobs(&tmpds)=&rows %then %do;
247
305
  proc sql;
248
- insert into &outds values("&lev1 &lev2 &lev3 &lev4 &lev5");
306
+ insert into &outds
307
+ values("&lev1 &lev2 &lev3 &lev4 &lev5 &lev6");
249
308
  %if %mf_nobs(&outds) ge &max_guesses %then %do;
250
- %put &sysmacroname: Max PKs reached at Level 5 for &baseds;
251
- %return;
252
- %end;
253
- %end;
254
- %end;
255
- %end;
256
- %end;
257
- %end;
258
- %end;
259
- %end;
260
-
261
- %if &ppkcnt=5 %then %do;
262
- %put &sysmacroname: No more PK guess possible;
263
- %return;
264
- %end;
265
-
266
- /* scan for uniques on up to 4 PK fields */
267
- %local lev6 n;
268
- %do i=1 %to &ppkcnt;
269
- %let lev1=%scan(&posspks,&i);
270
- %do j=2 %to &ppkcnt;
271
- %let lev2=%scan(&posspks,&j);
272
- %if &lev1 ne &lev2 %then %do k=3 %to &ppkcnt;
273
- %let lev3=%scan(&posspks,&k);
274
- %if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
275
- %let lev4=%scan(&posspks,&l);
276
- %if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
277
- %do m=5 %to &ppkcnt;
278
- %let lev5=%scan(&posspks,&m);
279
- %if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then
280
- %do n=6 %to &ppkcnt;
281
- %let lev6=%scan(&posspks,&n);
282
- %if &lev1 ne &lev6 & &lev2 ne &lev6 & &lev3 ne &lev6
283
- & &lev4 ne &lev6 & &lev5 ne &lev6 %then
284
- %do;
285
- /* check for four level uniqueness */
286
- proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5 &lev6)
287
- out=&tmpds noduprec;
288
- by _all_;
289
- run;
290
- %if %mf_nobs(&tmpds)=&rows %then %do;
291
- proc sql;
292
- insert into &outds
293
- values("&lev1 &lev2 &lev3 &lev4 &lev5 &lev6");
294
- %if %mf_nobs(&outds) ge &max_guesses %then %do;
295
- %put &sysmacroname: Max PKs reached at Level 6 for &baseds;
296
- %return;
297
- %end;
309
+ %put &sysmacroname: Max PKs reached at Level 6 for &baseds;
310
+ %goto exit;
298
311
  %end;
299
312
  %end;
300
313
  %end;
@@ -303,10 +316,17 @@
303
316
  %end;
304
317
  %end;
305
318
  %end;
306
-
307
- %if &ppkcnt=6 %then %do;
308
- %put &sysmacroname: No more PK guess possible;
309
- %return;
310
- %end;
319
+ %end;
320
+
321
+ %if &ppkcnt=6 %then %do;
322
+ %put &sysmacroname: No more PK guess possible;
323
+ %goto exit;
324
+ %end;
325
+
326
+ %exit:
327
+ %if &mdebug=0 %then %do;
328
+ proc sql;
329
+ drop table &tmpds;
330
+ %end;
311
331
 
312
332
  %mend mp_guesspk;
package/base/mp_init.sas CHANGED
@@ -33,37 +33,42 @@
33
33
  %macro mp_init(prefix=SASJS
34
34
  )/*/STORE SOURCE*/;
35
35
 
36
- %global
37
- &prefix._INIT_NUM /* initialisation time as numeric */
38
- &prefix._INIT_DTTM /* initialisation time in E8601DT26.6 format */
39
- &prefix.WORK /* avoid typing %sysfunc(pathname(work)) every time */
40
- ;
41
- %if %eval(&&&prefix._INIT_NUM>0) %then %return; /* only run once */
42
-
43
- data _null_;
44
- dttm=datetime();
45
- call symputx("&prefix._init_num",dttm,'g');
46
- call symputx("&prefix._init_dttm",put(dttm,E8601DT26.6),'g');
47
- call symputx("&prefix.work",pathname('WORK'),'g');
48
- run;
49
-
50
- options
51
- noautocorrect /* disallow misspelled procedure names */
52
- compress=CHAR /* default is none so ensure we have something! */
53
- datastmtchk=ALLKEYWORDS /* protection from overwriting input datasets */
54
- dsoptions=note2err /* undocumented - convert bad NOTEs to ERRs */
55
- %str(err)orcheck=STRICT /* catch errs in libname/filename statements */
56
- fmterr /* ensure err when a format cannot be found */
57
- mergenoby=%str(ERR)OR /* throw err when a merge has no BY variables */
58
- missing=. /* changing this can cause hard to detect errs */
59
- noquotelenmax /* avoid warnings for long strings */
60
- noreplace /* avoid overwriting permanent datasets */
61
- ps=max /* reduce log size slightly */
62
- ls=max /* reduce log even more and avoid word truncation */
63
- validmemname=COMPATIBLE /* avoid special characters etc in table names */
64
- validvarname=V7 /* avoid special characters etc in variable names */
65
- varinitchk=%str(ERR)OR /* avoid data mistakes from variable name typos */
66
- varlenchk=%str(ERR)OR /* fail hard if truncation (data loss) can result */
67
- ;
36
+ %if %symexist(SASJS_PREFIX) %then %return; /* only run once */
37
+
38
+ %global
39
+ SASJS_PREFIX /* the ONLY hard-coded global macro variable in SASjs */
40
+ &prefix._FUNCTIONS /* used in mcf_init() to track core function compilation */
41
+ &prefix._INIT_NUM /* initialisation time as numeric */
42
+ &prefix._INIT_DTTM /* initialisation time in E8601DT26.6 format */
43
+ &prefix.WORK /* avoid typing %sysfunc(pathname(work)) every time */
44
+ ;
45
+
46
+ %let sasjs_prefix=&prefix;
47
+
48
+ data _null_;
49
+ dttm=datetime();
50
+ call symputx("&sasjs_prefix._init_num",dttm,'g');
51
+ call symputx("&sasjs_prefix._init_dttm",put(dttm,E8601DT26.6),'g');
52
+ call symputx("&sasjs_prefix.work",pathname('WORK'),'g');
53
+ run;
54
+
55
+ options
56
+ noautocorrect /* disallow misspelled procedure names */
57
+ compress=CHAR /* default is none so ensure we have something! */
58
+ datastmtchk=ALLKEYWORDS /* protection from overwriting input datasets */
59
+ dsoptions=note2err /* undocumented - convert bad NOTEs to ERRs */
60
+ %str(err)orcheck=STRICT /* catch errs in libname/filename statements */
61
+ fmterr /* ensure err when a format cannot be found */
62
+ mergenoby=%str(ERR)OR /* throw err when a merge has no BY variables */
63
+ missing=. /* changing this can cause hard to detect errs */
64
+ noquotelenmax /* avoid warnings for long strings */
65
+ noreplace /* avoid overwriting permanent datasets */
66
+ ps=max /* reduce log size slightly */
67
+ ls=max /* reduce log even more and avoid word truncation */
68
+ validmemname=COMPATIBLE /* avoid special characters etc in table names */
69
+ validvarname=V7 /* avoid special characters etc in variable names */
70
+ varinitchk=%str(ERR)OR /* avoid data mistakes from variable name typos */
71
+ varlenchk=%str(ERR)OR /* fail hard if truncation (data loss) can result */
72
+ ;
68
73
 
69
74
  %mend mp_init;
@@ -62,7 +62,6 @@
62
62
 
63
63
  %macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y
64
64
  ,engine=DATASTEP
65
- ,dbg=0 /* DEPRECATED */
66
65
  ,missing=NULL
67
66
  ,showmeta=NO
68
67
  )/*/STORE SOURCE*/;