@sasjs/core 3.0.2 → 3.2.1

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.
@@ -0,0 +1,40 @@
1
+ /**
2
+ @file
3
+ @brief Checks whether a string follows correct library.dataset format
4
+ @details Many macros in the core library accept a library.dataset parameter
5
+ referred to as 'libds'. This macro validates the structure of that parameter,
6
+ eg:
7
+
8
+ @li 8 character libref?
9
+ @li 32 character dataset?
10
+ @li contains a period?
11
+
12
+ It does NOT check whether the dataset exists, or if the library is assigned.
13
+
14
+ Usage:
15
+
16
+ %put %mf_islibds(work.something)=1;
17
+ %put %mf_islibds(nolib)=0;
18
+ %put %mf_islibds(badlibref.ds)=0;
19
+ %put %mf_islibds(w.t.f)=0;
20
+
21
+ @param [in] libds The string to be checked
22
+
23
+ @return output Returns 1 if libds is valid, 0 if it is not
24
+
25
+ <h4> Related Macros </h4>
26
+ @li mf_islibds.test.sas
27
+ @li mp_validatecol.sas
28
+
29
+ @version 9.2
30
+ **/
31
+
32
+ %macro mf_islibds(libds
33
+ )/*/STORE SOURCE*/;
34
+
35
+ %local regex;
36
+ %let regex=%sysfunc(prxparse(%str(/^[_a-z]\w{0,7}\.[_a-z]\w{0,31}$/i)));
37
+
38
+ %sysfunc(prxmatch(&regex,&libds))
39
+
40
+ %mend mf_islibds;
@@ -0,0 +1,54 @@
1
+ /**
2
+ @file
3
+ @brief Returns words that are in both string 1 and string 2
4
+ @details Compares two space separated strings and returns the words that are
5
+ in both.
6
+ Usage:
7
+
8
+ %put %mf_wordsInStr1andStr2(
9
+ Str1=blah sss blaaah brah bram boo
10
+ ,Str2= blah blaaah brah ssss
11
+ );
12
+
13
+ returns:
14
+ > blah blaaah brah
15
+
16
+ @param str1= string containing words to extract
17
+ @param str2= used to compare with the extract string
18
+
19
+ @warning CASE SENSITIVE!
20
+
21
+ @version 9.2
22
+ @author Allan Bowe
23
+
24
+ **/
25
+
26
+ %macro mf_wordsInStr1andStr2(
27
+ Str1= /* string containing words to extract */
28
+ ,Str2= /* used to compare with the extract string */
29
+ )/*/STORE SOURCE*/;
30
+
31
+ %local count_base count_extr i i2 extr_word base_word match outvar;
32
+ %if %length(&str1)=0 or %length(&str2)=0 %then %do;
33
+ %put %str(WARN)ING: empty string provided!;
34
+ %put base string (str1)= &str1;
35
+ %put compare string (str2) = &str2;
36
+ %return;
37
+ %end;
38
+ %let count_base=%sysfunc(countw(&Str2));
39
+ %let count_extr=%sysfunc(countw(&Str1));
40
+
41
+ %do i=1 %to &count_extr;
42
+ %let extr_word=%scan(&Str1,&i,%str( ));
43
+ %let match=0;
44
+ %do i2=1 %to &count_base;
45
+ %let base_word=%scan(&Str2,&i2,%str( ));
46
+ %if &extr_word=&base_word %then %let match=1;
47
+ %end;
48
+ %if &match=1 %then %let outvar=&outvar &extr_word;
49
+ %end;
50
+
51
+ &outvar
52
+
53
+ %mend mf_wordsInStr1andStr2;
54
+
@@ -62,13 +62,13 @@
62
62
  %put output location=&jref;
63
63
  %if &action=OPEN %then %do;
64
64
  options nobomfile;
65
- data _null_;file &jref encoding='utf-8' termstr=lf;
65
+ data _null_;file &jref encoding='utf-8' ;
66
66
  put '{"PROCESSED_DTTM" : "' "%sysfunc(datetime(),E8601DT26.6)" '"';
67
67
  run;
68
68
  %end;
69
69
  %else %if (&action=ARR or &action=OBJ) %then %do;
70
70
  options validvarname=upcase;
71
- data _null_;file &jref mod encoding='utf-8' termstr=lf;
71
+ data _null_;file &jref mod encoding='utf-8' ;
72
72
  put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":";
73
73
 
74
74
  %if &engine=PROCJSON %then %do;
@@ -147,7 +147,7 @@
147
147
  run;
148
148
  %let ds=&fmtds;
149
149
  %end; /* &fmt=Y */
150
- data _null_;file &jref mod encoding='utf-8' termstr=lf;
150
+ data _null_;file &jref mod encoding='utf-8' ;
151
151
  put "["; call symputx('cols',0,'l');
152
152
  proc sort
153
153
  data=sashelp.vcolumn(where=(libname='WORK' & memname="%upcase(&ds)"))
@@ -192,7 +192,7 @@
192
192
  /* write to temp loc to avoid _webout truncation
193
193
  - https://support.sas.com/kb/49/325.html */
194
194
  filename _sjs temp lrecl=131068 encoding='utf-8';
195
- data _null_; file _sjs lrecl=131068 encoding='utf-8' mod termstr=lf;
195
+ data _null_; file _sjs lrecl=131068 encoding='utf-8' mod ;
196
196
  set &tempds;
197
197
  if _n_>1 then put "," @; put
198
198
  %if &action=ARR %then "[" ; %else "{" ;
@@ -219,14 +219,14 @@
219
219
  rc = fclose(fileid);
220
220
  run;
221
221
  filename _sjs clear;
222
- data _null_; file &jref mod encoding='utf-8' termstr=lf;
222
+ data _null_; file &jref mod encoding='utf-8' ;
223
223
  put "]";
224
224
  run;
225
225
  %end;
226
226
  %end;
227
227
 
228
228
  %else %if &action=CLOSE %then %do;
229
- data _null_;file &jref encoding='utf-8' mod termstr=lf;
229
+ data _null_;file &jref encoding='utf-8' mod ;
230
230
  put "}";
231
231
  run;
232
232
  %end;
@@ -10,8 +10,6 @@
10
10
  according to the variable types and formats.
11
11
 
12
12
  TODO:
13
- @li Respect PKs
14
- @li Respect NOT NULLs
15
13
  @li Consider dates, datetimes, times, integers etc
16
14
 
17
15
  Usage:
@@ -27,16 +25,23 @@
27
25
  );
28
26
  %mp_makedata(work.example)
29
27
 
30
- @param [in] libds The empty table in which to create data
31
- @param [out] obs= (500) The number of records to create.
28
+ @param [in] libds The empty table (libref.dataset) in which to create data
29
+ @param [out] obs= (500) The maximum number of records to create. The table
30
+ is sorted with nodup on the primary key, so the actual number of records may
31
+ be lower than this.
32
32
 
33
33
  <h4> SAS Macros </h4>
34
34
  @li mf_getuniquename.sas
35
35
  @li mf_getvarlen.sas
36
+ @li mf_getvarlist.sas
37
+ @li mf_islibds.sas
36
38
  @li mf_nobs.sas
37
39
  @li mp_getcols.sas
38
40
  @li mp_getpk.sas
39
41
 
42
+ <h4> Related Macros </h4>
43
+ @li mp_makedata.test.sas
44
+
40
45
  @version 9.2
41
46
  @author Allan Bowe
42
47
 
@@ -44,44 +49,58 @@
44
49
 
45
50
  %macro mp_makedata(libds
46
51
  ,obs=500
52
+ ,seed=1
47
53
  )/*/STORE SOURCE*/;
48
54
 
49
- %local ds1 c1 n1 i col charvars numvars;
55
+ %local ds1 ds2 lib ds pk_fields i col charvars numvars ispk;
50
56
 
51
- %if %mf_nobs(&libds)>0 %then %do;
57
+ %if %mf_islibds(&libds)=0 %then %do;
58
+ %put &sysmacroname: Invalid libds (&libds) - should be library.dataset format;
59
+ %return;
60
+ %end;
61
+ %else %if %mf_nobs(&libds)>0 %then %do;
52
62
  %put &sysmacroname: &libds has data, it will not be recreated;
53
63
  %return;
54
64
  %end;
55
65
 
56
- %local ds1 c1 n1;
57
- %let ds1=%mf_getuniquename(prefix=mp_makedata);
58
- %let c1=%mf_getuniquename(prefix=mp_makedatacol);
59
- %let n1=%mf_getuniquename(prefix=mp_makedatacol);
60
- data &ds1;
66
+ /* set up temporary vars */
67
+ %let ds1=%mf_getuniquename(prefix=mp_makedatads1);
68
+ %let ds2=%mf_getuniquename(prefix=mp_makedatads2);
69
+ %let lib=%scan(&libds,1,.);
70
+ %let ds=%scan(&libds,2,.);
71
+
72
+ /* grab the primary key vars */
73
+ %mp_getpk(&lib,ds=&ds,outds=&ds1)
74
+
75
+ proc sql noprint;
76
+ select coalescec(pk_fields,'_all_') into: pk_fields from &ds1;
77
+
78
+ data &ds2;
61
79
  if 0 then set &libds;
62
80
  do _n_=1 to &obs;
63
- &c1=repeat(uuidgen(),10);
64
- &n1=ranuni(1)*5000000;
65
- drop &c1 &n1;
66
81
  %let charvars=%mf_getvarlist(&libds,typefilter=C);
67
82
  %if &charvars ^= %then %do i=1 %to %sysfunc(countw(&charvars));
68
83
  %let col=%scan(&charvars,&i);
69
- &col=subpad(&c1,1,%mf_getvarlen(&libds,&col));
84
+ /* create random value based on observation number and colum length */
85
+ &col=repeat(put(md5(cats(_n_)),$hex32.),%mf_getvarlen(&libds,&col)/32);
70
86
  %end;
71
87
 
72
88
  %let numvars=%mf_getvarlist(&libds,typefilter=N);
73
89
  %if &numvars ^= %then %do i=1 %to %sysfunc(countw(&numvars));
74
90
  %let col=%scan(&numvars,&i);
75
- &col=&n1;
91
+ &col=_n_;
76
92
  %end;
77
93
  output;
78
94
  end;
79
95
  run;
96
+ proc sort data=&ds2 nodupkey;
97
+ by &pk_fields;
98
+ run;
80
99
 
81
- proc append base=&libds data=&ds1;
100
+ proc append base=&libds data=&ds2;
82
101
  run;
83
102
 
84
103
  proc sql;
85
- drop table &ds1;
104
+ drop table &ds1, &ds2;
86
105
 
87
106
  %mend mp_makedata;
@@ -3,13 +3,15 @@
3
3
  @brief Reset an option to original value
4
4
  @details Inspired by the SAS Jedi -
5
5
  https://blogs.sas.com/content/sastraining/2012/08/14/jedi-sas-tricks-reset-sas-system-options
6
- Called as follows:
7
6
 
8
- options obs=30;
9
- %mp_resetoption(OBS)
7
+ Called as follows:
10
8
 
9
+ options obs=30 ps=max;
10
+ %mp_resetoption(OBS)
11
+ %mp_resetoption(PS)
11
12
 
12
- @param option the option to reset
13
+
14
+ @param [in] option the option to reset
13
15
 
14
16
  @version 9.2
15
17
  @author Allan Bowe
@@ -11,9 +11,7 @@
11
11
 
12
12
  This macro will only work for BASE (V9) engine libraries. It works by
13
13
  creating a copy of the dataset (without data, WITH constraints) in the same
14
- library, appending a sorted view into it, and finally - renaming it. By
15
- default, COMPRESS=CHAR and REUSE=YES will be applied, this behaviour can
16
- be adjusted using the `dsoptions=` parameter.
14
+ library, appending a sorted view into it, and finally - renaming it.
17
15
 
18
16
  Example usage:
19
17
 
@@ -41,7 +39,6 @@
41
39
 
42
40
  @version 9.2
43
41
  @author Allan Bowe
44
- @source https://github.com/sasjs/core
45
42
 
46
43
  **/
47
44
 
@@ -94,13 +94,13 @@ data _null_;
94
94
  put '%put output location=&jref; ';
95
95
  put '%if &action=OPEN %then %do; ';
96
96
  put ' options nobomfile; ';
97
- put ' data _null_;file &jref encoding=''utf-8''; ';
97
+ put ' data _null_;file &jref encoding=''utf-8'' ; ';
98
98
  put ' put ''{"PROCESSED_DTTM" : "'' "%sysfunc(datetime(),E8601DT26.6)" ''"''; ';
99
99
  put ' run; ';
100
100
  put '%end; ';
101
101
  put '%else %if (&action=ARR or &action=OBJ) %then %do; ';
102
102
  put ' options validvarname=upcase; ';
103
- put ' data _null_;file &jref mod encoding=''utf-8''; ';
103
+ put ' data _null_;file &jref mod encoding=''utf-8'' ; ';
104
104
  put ' put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":"; ';
105
105
  put ' ';
106
106
  put ' %if &engine=PROCJSON %then %do; ';
@@ -179,7 +179,7 @@ data _null_;
179
179
  put ' run; ';
180
180
  put ' %let ds=&fmtds; ';
181
181
  put ' %end; /* &fmt=Y */ ';
182
- put ' data _null_;file &jref mod encoding=''utf-8''; ';
182
+ put ' data _null_;file &jref mod encoding=''utf-8'' ; ';
183
183
  put ' put "["; call symputx(''cols'',0,''l''); ';
184
184
  put ' proc sort ';
185
185
  put ' data=sashelp.vcolumn(where=(libname=''WORK'' & memname="%upcase(&ds)")) ';
@@ -224,7 +224,7 @@ data _null_;
224
224
  put ' /* write to temp loc to avoid _webout truncation ';
225
225
  put ' - https://support.sas.com/kb/49/325.html */ ';
226
226
  put ' filename _sjs temp lrecl=131068 encoding=''utf-8''; ';
227
- put ' data _null_; file _sjs lrecl=131068 encoding=''utf-8'' mod; ';
227
+ put ' data _null_; file _sjs lrecl=131068 encoding=''utf-8'' mod ; ';
228
228
  put ' set &tempds; ';
229
229
  put ' if _n_>1 then put "," @; put ';
230
230
  put ' %if &action=ARR %then "[" ; %else "{" ; ';
@@ -251,14 +251,14 @@ data _null_;
251
251
  put ' rc = fclose(fileid); ';
252
252
  put ' run; ';
253
253
  put ' filename _sjs clear; ';
254
- put ' data _null_; file &jref mod encoding=''utf-8''; ';
254
+ put ' data _null_; file &jref mod encoding=''utf-8'' ; ';
255
255
  put ' put "]"; ';
256
256
  put ' run; ';
257
257
  put ' %end; ';
258
258
  put '%end; ';
259
259
  put ' ';
260
260
  put '%else %if &action=CLOSE %then %do; ';
261
- put ' data _null_;file &jref encoding=''utf-8'' mod; ';
261
+ put ' data _null_;file &jref encoding=''utf-8'' mod ; ';
262
262
  put ' put "}"; ';
263
263
  put ' run; ';
264
264
  put '%end; ';
package/package.json CHANGED
@@ -38,5 +38,5 @@
38
38
  "dependencies": {
39
39
  "ts-loader": "^9.2.6"
40
40
  },
41
- "version": "3.0.2"
41
+ "version": "3.2.1"
42
42
  }
@@ -242,13 +242,13 @@ data _null_;
242
242
  put '%put output location=&jref; ';
243
243
  put '%if &action=OPEN %then %do; ';
244
244
  put ' options nobomfile; ';
245
- put ' data _null_;file &jref encoding=''utf-8''; ';
245
+ put ' data _null_;file &jref encoding=''utf-8'' ; ';
246
246
  put ' put ''{"PROCESSED_DTTM" : "'' "%sysfunc(datetime(),E8601DT26.6)" ''"''; ';
247
247
  put ' run; ';
248
248
  put '%end; ';
249
249
  put '%else %if (&action=ARR or &action=OBJ) %then %do; ';
250
250
  put ' options validvarname=upcase; ';
251
- put ' data _null_;file &jref mod encoding=''utf-8''; ';
251
+ put ' data _null_;file &jref mod encoding=''utf-8'' ; ';
252
252
  put ' put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":"; ';
253
253
  put ' ';
254
254
  put ' %if &engine=PROCJSON %then %do; ';
@@ -327,7 +327,7 @@ data _null_;
327
327
  put ' run; ';
328
328
  put ' %let ds=&fmtds; ';
329
329
  put ' %end; /* &fmt=Y */ ';
330
- put ' data _null_;file &jref mod encoding=''utf-8''; ';
330
+ put ' data _null_;file &jref mod encoding=''utf-8'' ; ';
331
331
  put ' put "["; call symputx(''cols'',0,''l''); ';
332
332
  put ' proc sort ';
333
333
  put ' data=sashelp.vcolumn(where=(libname=''WORK'' & memname="%upcase(&ds)")) ';
@@ -372,7 +372,7 @@ data _null_;
372
372
  put ' /* write to temp loc to avoid _webout truncation ';
373
373
  put ' - https://support.sas.com/kb/49/325.html */ ';
374
374
  put ' filename _sjs temp lrecl=131068 encoding=''utf-8''; ';
375
- put ' data _null_; file _sjs lrecl=131068 encoding=''utf-8'' mod; ';
375
+ put ' data _null_; file _sjs lrecl=131068 encoding=''utf-8'' mod ; ';
376
376
  put ' set &tempds; ';
377
377
  put ' if _n_>1 then put "," @; put ';
378
378
  put ' %if &action=ARR %then "[" ; %else "{" ; ';
@@ -399,14 +399,14 @@ data _null_;
399
399
  put ' rc = fclose(fileid); ';
400
400
  put ' run; ';
401
401
  put ' filename _sjs clear; ';
402
- put ' data _null_; file &jref mod encoding=''utf-8''; ';
402
+ put ' data _null_; file &jref mod encoding=''utf-8'' ; ';
403
403
  put ' put "]"; ';
404
404
  put ' run; ';
405
405
  put ' %end; ';
406
406
  put '%end; ';
407
407
  put ' ';
408
408
  put '%else %if &action=CLOSE %then %do; ';
409
- put ' data _null_;file &jref encoding=''utf-8'' mod; ';
409
+ put ' data _null_;file &jref encoding=''utf-8'' mod ; ';
410
410
  put ' put "}"; ';
411
411
  put ' run; ';
412
412
  put '%end; ';