@sasjs/core 4.21.4 → 4.22.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.
@@ -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));
@@ -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.22.0"
39
39
  }