@sasjs/core 4.21.4 → 4.23.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,42 @@
1
+ /**
2
+ @file
3
+ @brief Returns E8601DT26.6 if compatible else DATETIME19.3
4
+ @details From our experience in [Data Controller for SAS]
5
+ (https://datacontroller.io) deployments, the E8601DT26.6 datetime format has
6
+ the widest support when it comes to pass-through SQL queries.
7
+
8
+ However, it is not supported in WPS or early versions of SAS 9 (M3 and below)
9
+ when used as a datetime literal, eg:
10
+
11
+ data _null_;
12
+ demo="%sysfunc(datetime(),E8601DT26.6)"dt;
13
+ demo=;
14
+ run;
15
+
16
+ This macro will therefore return DATEITME19.3 as an alternative format
17
+ based on the runtime environment so that it can be used in such cases, eg:
18
+
19
+ data _null_;
20
+ demo="%sysfunc(datetime(),%mf_fmtdttm())"dt;
21
+ demo=;
22
+ run;
23
+
24
+ <h4> Related Macros </h4>
25
+ @li mf_fmtdttm.test.sas
26
+
27
+ @author Allan Bowe
28
+ **/
29
+
30
+ %macro mf_fmtdttm(
31
+ )/*/STORE SOURCE*/;
32
+
33
+ %if "&sysver"="9.2" or "&sysver"="9.3"
34
+ or ("&sysver"="9.4" and "%substr(&SYSVLONG,9,1)" le "3")
35
+ or "%substr(&sysver,1,1)"="4"
36
+ or "%substr(&sysver,1,1)"="5"
37
+ %then %do;DATETIME19.3%end;
38
+ %else %do;E8601DT26.6%end;
39
+
40
+ %mend mf_fmtdttm;
41
+
42
+
@@ -3,12 +3,12 @@
3
3
  @brief Returns an unused libref
4
4
  @details Use as follows:
5
5
 
6
- libname mclib0 (work);
7
- libname mclib1 (work);
8
- libname mclib2 (work);
6
+ libname mclib0 (work);
7
+ libname mclib1 (work);
8
+ libname mclib2 (work);
9
9
 
10
- %let libref=%mf_getuniquelibref();
11
- %put &=libref;
10
+ %let libref=%mf_getuniquelibref();
11
+ %put &=libref;
12
12
 
13
13
  which returns:
14
14
 
@@ -2,31 +2,48 @@
2
2
  @file
3
3
  @brief Returns number of variables in a dataset
4
4
  @details Useful to identify those renagade datasets that have no columns!
5
+ Can also be used to count for numeric, or character columns
5
6
 
6
- %put Number of Variables=%mf_getvarcount(sashelp.class);
7
+ %put Number of Variables=%mf_getvarcount(sashelp.class);
8
+ %put Character Variables=%mf_getvarcount(sashelp.class,typefilter=C);
9
+ %put Numeric Variables = %mf_getvarcount(sashelp.class,typefilter=N);
7
10
 
8
11
  returns:
9
12
  > Number of Variables=4
10
13
 
11
- @param libds Two part dataset (or view) reference.
14
+
15
+ @param [in] libds Two part dataset (or view) reference.
16
+ @param [in] typefilter= (A) Filter for certain types of column. Valid values:
17
+ @li A Count All columns
18
+ @li C Count Character columns only
19
+ @li N Count Numeric columns only
12
20
 
13
21
  @version 9.2
14
22
  @author Allan Bowe
15
23
 
16
24
  **/
17
25
 
18
- %macro mf_getvarcount(libds
26
+ %macro mf_getvarcount(libds,typefilter=A
19
27
  )/*/STORE SOURCE*/;
20
- %local dsid nvars rc ;
28
+ %local dsid nvars rc outcnt x;
21
29
  %let dsid=%sysfunc(open(&libds));
22
30
  %let nvars=.;
31
+ %let outcnt=0;
32
+ %let typefilter=%upcase(&typefilter);
23
33
  %if &dsid %then %do;
24
34
  %let nvars=%sysfunc(attrn(&dsid,NVARS));
35
+ %if &typefilter=A %then %let outcnt=&nvars;
36
+ %else %if &nvars>0 %then %do x=1 %to &nvars;
37
+ /* increment based on variable type */
38
+ %if %sysfunc(vartype(&dsid,&x))=&typefilter %then %do;
39
+ %let outcnt=%eval(&outcnt+1);
40
+ %end;
41
+ %end;
25
42
  %let rc=%sysfunc(close(&dsid));
26
43
  %end;
27
44
  %else %do;
28
45
  %put unable to open &libds (rc=&dsid);
29
46
  %let rc=%sysfunc(close(&dsid));
30
47
  %end;
31
- &nvars
48
+ &outcnt
32
49
  %mend mf_getvarcount;
package/base/mp_abort.sas CHANGED
@@ -89,7 +89,12 @@
89
89
  or "&SYSPROCESSNAME "="Compute Server "
90
90
  or &mode=INCLUDE
91
91
  %then %do;
92
- options obs=max replace nosyntaxcheck mprint;
92
+ options obs=max replace mprint;
93
+ %if "%substr(&sysver,1,1)" ne "4" and "%substr(&sysver,1,1)" ne "5"
94
+ %then %do;
95
+ options nosyntaxcheck;
96
+ %end;
97
+
93
98
  %if &mode=INCLUDE %then %do;
94
99
  %if %sysfunc(exist(&errds))=1 %then %do;
95
100
  data _null_;
@@ -41,6 +41,7 @@
41
41
  <h4> SAS Macros </h4>
42
42
  @li mcf_length.sas
43
43
  @li mf_getuniquename.sas
44
+ @li mf_getvarcount.sas
44
45
  @li mf_getvarlist.sas
45
46
  @li mf_getvartype.sas
46
47
  @li mf_getvarformat.sas
@@ -60,7 +61,7 @@
60
61
  ,outds=work.mp_getmaxvarlengths
61
62
  )/*/STORE SOURCE*/;
62
63
 
63
- %local vars prefix x var fmt;
64
+ %local vars prefix x var fmt srcds;
64
65
  %let vars=%mf_getvarlist(libds=&libds);
65
66
  %let prefix=%substr(%mf_getuniquename(),1,25);
66
67
  %let num2char=%upcase(&num2char);
@@ -70,6 +71,24 @@
70
71
  %mcf_length(wrap=YES, insert_cmplib=YES)
71
72
  %end;
72
73
 
74
+ %if &num2char=NO
75
+ and ("%substr(&sysver,1,1)"="4" or "%substr(&sysver,1,1)"="5")
76
+ and %mf_getvarcount(&libds,typefilter=N) gt 0
77
+ %then %do;
78
+ /* custom functions not supported in summary operations */
79
+ %let srcds=%mf_getuniquename();
80
+ data &srcds/view=&srcds;
81
+ set &libds;
82
+ %do x=1 %to %sysfunc(countw(&vars,%str( )));
83
+ %let var=%scan(&vars,&x);
84
+ %if %mf_getvartype(&libds,&var)=N %then %do;
85
+ &prefix.&x=mcf_length(&var);
86
+ %end;
87
+ %end;
88
+ run;
89
+ %end;
90
+ %else %let srcds=&libds;
91
+
73
92
  proc sql;
74
93
  create table &outds (rename=(
75
94
  %do x=1 %to %sysfunc(countw(&vars,%str( )));
@@ -94,10 +113,15 @@ create table &outds (rename=(
94
113
  %end;
95
114
  %end;
96
115
  %else %do;
97
- max(mcf_length(&var)) as &prefix.&x
116
+ %if "%substr(&sysver,1,1)"="4" or "%substr(&sysver,1,1)"="5" %then %do;
117
+ max(&prefix.&x) as &prefix.&x
118
+ %end;
119
+ %else %do;
120
+ max(mcf_length(&var)) as &prefix.&x
121
+ %end;
98
122
  %end;
99
123
  %end;
100
- from &libds;
124
+ from &srcds;
101
125
 
102
126
  proc transpose data=&outds
103
127
  out=&outds(rename=(_name_=NAME COL1=MAXLEN));
@@ -22,6 +22,7 @@
22
22
  @param [in] loop_secs= (1) Seconds to wait between each lock attempt
23
23
 
24
24
  <h4> SAS Macros </h4>
25
+ @li mf_fmtdttm.sas
25
26
  @li mp_abort.sas
26
27
  @li mp_lockfilecheck.sas
27
28
  @li mf_getuser.sas
@@ -111,7 +112,7 @@ run;
111
112
  LOCK_LIB ="&lib";
112
113
  LOCK_DS="&ds";
113
114
  LOCK_STATUS_CD='LOCKED';
114
- LOCK_START_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt;
115
+ LOCK_START_DTTM="%sysfunc(datetime(),%mf_fmtdttm())"dt;
115
116
  LOCK_USER_NM="&user";
116
117
  LOCK_PID="&sysjobid";
117
118
  LOCK_REF="&ref";
@@ -131,7 +132,7 @@ run;
131
132
  proc sql;
132
133
  update &ctl_ds
133
134
  set LOCK_STATUS_CD='LOCKED'
134
- , LOCK_START_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt
135
+ , LOCK_START_DTTM="%sysfunc(datetime(),%mf_fmtdttm())"dt
135
136
  , LOCK_USER_NM="&user"
136
137
  , LOCK_PID="&sysjobid"
137
138
  , LOCK_REF="&ref"
@@ -206,7 +207,7 @@ run;
206
207
  proc sql;
207
208
  update &ctl_ds
208
209
  set LOCK_STATUS_CD='UNLOCKED'
209
- , LOCK_END_DTTM="%sysfunc(datetime(),E8601DT26.6)"dt
210
+ , LOCK_END_DTTM="%sysfunc(datetime(),%mf_fmtdttm())"dt
210
211
  , LOCK_USER_NM="&user"
211
212
  , LOCK_PID="&sysjobid"
212
213
  , LOCK_REF="&ref"
@@ -58,6 +58,7 @@
58
58
 
59
59
  <h4> SAS Macros </h4>
60
60
  @li mf_existvar.sas
61
+ @li mf_fmtdttm.sas
61
62
  @li mf_getquotedstr.sas
62
63
  @li mf_getuniquename.sas
63
64
  @li mf_nobs.sas
@@ -217,12 +218,12 @@ quit;
217
218
  set keytable="&base_libds"
218
219
  ,keycolumn="&retained_key"
219
220
  ,max_key=%eval(&maxkey+&newkey_cnt)
220
- ,processed_dttm="%sysfunc(datetime(),E8601DT26.6)"dt;
221
+ ,processed_dttm="%sysfunc(datetime(),%mf_fmtdttm())"dt;
221
222
  %end;
222
223
  %else %do;
223
224
  update &maxkeytable
224
225
  set max_key=%eval(&maxkey+&newkey_cnt)
225
- ,processed_dttm="%sysfunc(datetime(),E8601DT26.6)"dt
226
+ ,processed_dttm="%sysfunc(datetime(),%mf_fmtdttm())"dt
226
227
  where keytable="&base_libds";
227
228
  %end;
228
229
  %mp_lockanytable(UNLOCK
@@ -125,7 +125,7 @@
125
125
  data &ds1;
126
126
  set &dslist indsname=&inds_auto;
127
127
  &hashkey=put(md5(catx('|',%mf_getquotedstr(&key,quote=N))),$hex32.);
128
- &inds_keep=&inds_auto;
128
+ &inds_keep=upcase(&inds_auto);
129
129
  proc sort;
130
130
  by &inds_keep &hashkey;
131
131
  run;
@@ -160,8 +160,8 @@ data &ds4;
160
160
  tgtvar_nm=upcase(tgtvar_nm);
161
161
  if tgtvar_nm in (%upcase(&vlist));
162
162
 
163
- if &inds_auto="&ds2" then tgtvar_type='N';
164
- else if &inds_auto="&ds3" then tgtvar_type='C';
163
+ if upcase(&inds_auto)="&ds2" then tgtvar_type='N';
164
+ else if upcase(&inds_auto)="&ds3" then tgtvar_type='C';
165
165
  else do;
166
166
  putlog "%str(ERR)OR: unidentified vartype input!" &inds_auto;
167
167
  call symputx('syscc',98);
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "3.13.0"
37
37
  },
38
- "version": "4.21.4"
38
+ "version": "4.23.1"
39
39
  }
@@ -68,8 +68,8 @@ data _null_;
68
68
  file &fname1 lrecl=1000;
69
69
  infile "&_sasjs_tokenfile" lrecl=1000;
70
70
  input;
71
- put "Content-Type: multipart/form-data; boundary=&boundary";
72
- put "Authorization: Bearer " _infile_;
71
+ if _n_=1 then put "Content-Type: multipart/form-data; boundary=&boundary";
72
+ put _infile_;
73
73
  run;
74
74
 
75
75
  %if &mdebug=1 %then %do;
@@ -87,9 +87,11 @@ data _null_;
87
87
  file &fref1 lrecl=1000;
88
88
  infile "&_sasjs_tokenfile" lrecl=1000;
89
89
  input;
90
- put "Authorization: Bearer " _infile_;
91
- put "Content-Type: application/json";
92
- put "accept: application/json";
90
+ if _n_=1 then do;
91
+ put "Content-Type: application/json";
92
+ put "accept: application/json";
93
+ end;
94
+ put _infile_;
93
95
  run;
94
96
 
95
97
  %if &mdebug=1 %then %do;
@@ -33,7 +33,7 @@ data _null_;
33
33
  file &headref lrecl=1000;
34
34
  infile "&_sasjs_tokenfile" lrecl=1000;
35
35
  input;
36
- put "Authorization: Bearer " _infile_;
36
+ put _infile_;
37
37
  run;
38
38
 
39
39
  proc http method='DELETE' headerin=&headref
@@ -34,7 +34,7 @@ data _null_;
34
34
  file &headref lrecl=1000;
35
35
  infile "&_sasjs_tokenfile" lrecl=1000;
36
36
  input;
37
- put "Authorization: Bearer " _infile_;
37
+ put _infile_;
38
38
  run;
39
39
 
40
40
  proc http method='GET' out=&binaryfref headerin=&headref
@@ -56,8 +56,8 @@ data _null_;
56
56
  file &fref0 lrecl=1000;
57
57
  infile "&_sasjs_tokenfile" lrecl=1000;
58
58
  input;
59
- put "Authorization: Bearer " _infile_;
60
- put "accept: application/json";
59
+ if _n_=1 then put "accept: application/json";
60
+ put _infile_;
61
61
  run;
62
62
 
63
63
  %if &mdebug=1 %then %do;
@@ -137,8 +137,8 @@ data _null_;
137
137
  file &authref lrecl=1000;
138
138
  infile "&_sasjs_tokenfile" lrecl=1000;
139
139
  input;
140
- put 'Authorization: Bearer ' _infile_;
141
- put "Content-Type: multipart/form-data; boundary=&boundary";
140
+ if _n_=1 then put "Content-Type: multipart/form-data; boundary=&boundary";
141
+ put _infile_;
142
142
  run;
143
143
 
144
144
  %if &mdebug=1 %then %do;