@sasjs/core 4.3.1 → 4.3.2
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.
- package/README.md +2 -0
- package/base/mp_abort.sas +4 -1
- package/base/mp_ds2csv.sas +54 -5
- package/base/mp_include.sas +4 -3
- package/fcmp/mcf_getfmttype.sas +12 -4
- package/fcmp/mcf_length.sas +12 -5
- package/fcmp/mcf_stpsrv_header.sas +12 -5
- package/fcmp/mcf_string2file.sas +12 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -196,6 +196,8 @@ When contributing to this library, it is therefore important to ensure that all
|
|
|
196
196
|
We are currently on major release v4. Breaking changes should be marked with the [deprecated](https://www.doxygen.nl/manual/commands.html#cmddeprecated) doxygen tag. The following changes are planned when the next major (breaking) release becomes necessary:
|
|
197
197
|
|
|
198
198
|
* mp_testservice.sas to be renamed as mp_execute.sas (as it doesn't actually test anything)
|
|
199
|
+
* `insert_cmplib` option of mcf_xxx macros will be deprecated (the option is now checked automatically with value inserted only if needed)
|
|
200
|
+
* mcf_xxx macros to have `wrap=` option defaulted to YES for convenience
|
|
199
201
|
|
|
200
202
|
## Star Gazing
|
|
201
203
|
|
package/base/mp_abort.sas
CHANGED
|
@@ -66,7 +66,10 @@
|
|
|
66
66
|
%if %length(&mac)>0 %then %put NOTE- called by &mac;
|
|
67
67
|
%put NOTE - &msg;
|
|
68
68
|
|
|
69
|
-
%if %symexist(_SYSINCLUDEFILEDEVICE)
|
|
69
|
+
%if %symexist(_SYSINCLUDEFILEDEVICE)
|
|
70
|
+
/* abort cancel FILE does not restart outside the INCLUDE on Viya 3.5 */
|
|
71
|
+
and "&SYSPROCESSNAME " ne "Compute Server "
|
|
72
|
+
%then %do;
|
|
70
73
|
%if "*&_SYSINCLUDEFILEDEVICE*" ne "**" %then %do;
|
|
71
74
|
data &errds;
|
|
72
75
|
iftrue='1=1';
|
package/base/mp_ds2csv.sas
CHANGED
|
@@ -3,10 +3,28 @@
|
|
|
3
3
|
@brief Export a dataset to a CSV file WITH leading blanks
|
|
4
4
|
@details Export a dataset to a file or fileref, retaining leading blanks.
|
|
5
5
|
|
|
6
|
+
When using SASJS headerformat, the input statement is provided in the first
|
|
7
|
+
row of the CSV.
|
|
8
|
+
|
|
6
9
|
Usage:
|
|
7
10
|
|
|
8
11
|
%mp_ds2csv(sashelp.class,outref="%sysfunc(pathname(work))/file.csv")
|
|
9
12
|
|
|
13
|
+
filename example temp;
|
|
14
|
+
%mp_ds2csv(sashelp.air,outref=example,headerformat=SASJS)
|
|
15
|
+
data; infile example; input;put _infile_; if _n_>5 then stop;run;
|
|
16
|
+
|
|
17
|
+
data _null_;
|
|
18
|
+
infile example;
|
|
19
|
+
input;
|
|
20
|
+
call symputx('stmnt',_infile_);
|
|
21
|
+
stop;
|
|
22
|
+
run;
|
|
23
|
+
data work.want;
|
|
24
|
+
infile example dsd firstobs=2;
|
|
25
|
+
input &stmnt;
|
|
26
|
+
run;
|
|
27
|
+
|
|
10
28
|
Why use mp_ds2csv over, say, proc export?
|
|
11
29
|
|
|
12
30
|
1. Ability to retain leading blanks (this is a major one)
|
|
@@ -23,7 +41,12 @@
|
|
|
23
41
|
@li LABEL - Use the variable label (or name, if blank)
|
|
24
42
|
@li NAME - Use the variable name
|
|
25
43
|
@li SASJS - Used to create sasjs-formatted input CSVs, eg for use in
|
|
26
|
-
mp_testservice.sas
|
|
44
|
+
mp_testservice.sas. This format will supply an input statement in the
|
|
45
|
+
first row, making ingestion by datastep a breeze. Special misisng values
|
|
46
|
+
will be prefixed with a period (eg `.A`) to enable ingestion on both SAS 9
|
|
47
|
+
and Viya. Dates / Datetimes etc are identified by the format type (lookup
|
|
48
|
+
with mcf_getfmttype.sas) and converted to human readable formats (not
|
|
49
|
+
numbers).
|
|
27
50
|
@param [out] outfile= The output filename - should be quoted.
|
|
28
51
|
@param [out] outref= (0) The output fileref (takes precedence if provided)
|
|
29
52
|
@param [in] outencoding= (0) The output encoding to use (unquoted)
|
|
@@ -33,7 +56,9 @@
|
|
|
33
56
|
@li LF
|
|
34
57
|
|
|
35
58
|
<h4> SAS Macros </h4>
|
|
59
|
+
@li mcf_getfmttype.sas
|
|
36
60
|
@li mf_getuniquename.sas
|
|
61
|
+
@li mf_getvarformat.sas
|
|
37
62
|
@li mf_getvarlist.sas
|
|
38
63
|
@li mf_getvartype.sas
|
|
39
64
|
|
|
@@ -50,7 +75,7 @@
|
|
|
50
75
|
,termstr=CRLF
|
|
51
76
|
)/*/STORE SOURCE*/;
|
|
52
77
|
|
|
53
|
-
%local outloc delim i varlist var vcnt vat dsv vcom vmiss;
|
|
78
|
+
%local outloc delim i varlist var vcnt vat dsv vcom vmiss fmttype vfmt;
|
|
54
79
|
|
|
55
80
|
%if not %sysfunc(exist(&ds)) %then %do;
|
|
56
81
|
%put %str(WARN)ING: &ds does not exist;
|
|
@@ -68,6 +93,7 @@
|
|
|
68
93
|
%if &headerformat=SASJS %then %do;
|
|
69
94
|
%let delim=",";
|
|
70
95
|
%let termstr=CRLF;
|
|
96
|
+
%mcf_getfmttype(wrap=YES)
|
|
71
97
|
%end;
|
|
72
98
|
%else %if &dlm=COMMA %then %let delim=",";
|
|
73
99
|
%else %let delim=";";
|
|
@@ -77,7 +103,8 @@
|
|
|
77
103
|
/* first get headers */
|
|
78
104
|
data _null_;
|
|
79
105
|
file &outloc &outencoding lrecl=32767 termstr=&termstr;
|
|
80
|
-
length header $ 2000 varnm $32 dlm $1;
|
|
106
|
+
length header $ 2000 varnm vfmt $32 dlm $1 fmttype $8;
|
|
107
|
+
call missing(of _all_);
|
|
81
108
|
dsid=open("&ds.","i");
|
|
82
109
|
num=attrn(dsid,"nvars");
|
|
83
110
|
dlm=&delim;
|
|
@@ -92,7 +119,14 @@ data _null_;
|
|
|
92
119
|
%end;
|
|
93
120
|
%else %if &headerformat=SASJS %then %do;
|
|
94
121
|
if vartype(dsid,i)='C' then header=cats(varnm,':$char',varlen(dsid,i),'.');
|
|
95
|
-
else
|
|
122
|
+
else do;
|
|
123
|
+
vfmt=coalescec(varfmt(dsid,i),'0');
|
|
124
|
+
fmttype=mcf_getfmttype(vfmt);
|
|
125
|
+
if fmttype='DATE' then header=cats(varnm,':date9.');
|
|
126
|
+
else if fmttype='DATETIME' then header=cats(varnm,':E8601DT26.6');
|
|
127
|
+
else if fmttype='TIME' then header=cats(varnm,':TIME12.');
|
|
128
|
+
else header=cats(varnm,':best.');
|
|
129
|
+
end;
|
|
96
130
|
%end;
|
|
97
131
|
%else %do;
|
|
98
132
|
%put &sysmacroname: Invalid headerformat value (&headerformat);
|
|
@@ -147,14 +181,29 @@ data _null_;
|
|
|
147
181
|
%let vcom=;
|
|
148
182
|
%end;
|
|
149
183
|
%if %mf_getvartype(&ds,&var)=N %then %do;
|
|
184
|
+
%if &headerformat = SASJS %then %do;
|
|
185
|
+
%let vcom=&delim;
|
|
186
|
+
%let fmttype=%sysfunc(mcf_getfmttype(%mf_getvarformat(&ds,&var)0));
|
|
187
|
+
%if &fmttype=DATE %then %let vfmt=DATE9.;
|
|
188
|
+
%else %if &fmttype=DATETIME %then %let vfmt=E8601DT26.6;
|
|
189
|
+
%else %if &fmttype=TIME %then %let vfmt=TIME12.;
|
|
190
|
+
%else %do;
|
|
191
|
+
%let vfmt=;
|
|
192
|
+
%let vcom=;
|
|
193
|
+
%end;
|
|
194
|
+
%end;
|
|
195
|
+
%else %let vcom=;
|
|
196
|
+
|
|
150
197
|
/* must use period - in order to work in both 9.4 and Viya 3.5 */
|
|
151
198
|
if missing(&var) and &var ne %sysfunc(getoption(MISSING)) then do;
|
|
152
199
|
&vmiss=cats('.',&var);
|
|
153
200
|
put &vmiss &vat;
|
|
154
201
|
end;
|
|
155
|
-
else put &var &vat;
|
|
202
|
+
else put &var &vfmt &vcom &vat;
|
|
203
|
+
|
|
156
204
|
%end;
|
|
157
205
|
%else %do;
|
|
206
|
+
%if &i ne &vcnt %then %let vcom=&delim;
|
|
158
207
|
put &var &&vlen&i &vcom &vat;
|
|
159
208
|
%end;
|
|
160
209
|
%end;
|
package/base/mp_include.sas
CHANGED
|
@@ -51,9 +51,10 @@ https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1j5tcc0n2xczyn1
|
|
|
51
51
|
this dataset.
|
|
52
52
|
It will then run an abort cancel FILE to stop the include running, and pass
|
|
53
53
|
the dataset back.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
|
|
55
|
+
IMPORTANT NOTE - it is NOT possible to read this dataset as part of _this_
|
|
56
|
+
macro! When running abort cancel FILE, ALL macros are closed, so instead it
|
|
57
|
+
is necessary to invoke "%mp_abort(mode=INCLUDE)" OUTSIDE of macro wrappers.
|
|
57
58
|
|
|
58
59
|
|
|
59
60
|
@version 9.4
|
package/fcmp/mcf_getfmttype.sas
CHANGED
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
> fmt3=TIME
|
|
32
32
|
|
|
33
33
|
@param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
|
|
34
|
-
@param [out] insert_cmplib= (NO) Choose YES to insert the package into the
|
|
35
|
-
CMPLIB reference.
|
|
36
34
|
@param [out] lib= (work) The output library in which to create the catalog.
|
|
37
35
|
@param [out] cat= (sasjs) The output catalog in which to create the package.
|
|
38
36
|
@param [out] pkg= (utils) The output package in which to create the function.
|
|
39
37
|
Uses a 3 part format: libref.catalog.package
|
|
38
|
+
@param [out] insert_cmplib= DEPRECATED - The CMPLIB option is checked and
|
|
39
|
+
values inserted only if needed.
|
|
40
40
|
|
|
41
41
|
<h4> SAS Macros </h4>
|
|
42
42
|
@li mcf_init.sas
|
|
@@ -51,11 +51,12 @@
|
|
|
51
51
|
**/
|
|
52
52
|
|
|
53
53
|
%macro mcf_getfmttype(wrap=NO
|
|
54
|
-
,insert_cmplib=
|
|
54
|
+
,insert_cmplib=DEPRECATED
|
|
55
55
|
,lib=WORK
|
|
56
56
|
,cat=SASJS
|
|
57
57
|
,pkg=UTILS
|
|
58
58
|
)/*/STORE SOURCE*/;
|
|
59
|
+
%local i var cmpval found;
|
|
59
60
|
|
|
60
61
|
%if %mcf_init(mcf_getfmttype)=1 %then %return;
|
|
61
62
|
|
|
@@ -103,7 +104,14 @@ endsub;
|
|
|
103
104
|
quit;
|
|
104
105
|
%end;
|
|
105
106
|
|
|
106
|
-
|
|
107
|
+
/* insert the CMPLIB if not already there */
|
|
108
|
+
%let cmpval=%sysfunc(getoption(cmplib));
|
|
109
|
+
%let found=0;
|
|
110
|
+
%do i=1 %to %sysfunc(countw(&cmpval,%str( %(%))));
|
|
111
|
+
%let var=%scan(&cmpval,&i,%str( %(%)));
|
|
112
|
+
%if &var=&lib..&cat %then %let found=1;
|
|
113
|
+
%end;
|
|
114
|
+
%if &found=0 %then %do;
|
|
107
115
|
options insert=(CMPLIB=(&lib..&cat));
|
|
108
116
|
%end;
|
|
109
117
|
|
package/fcmp/mcf_length.sas
CHANGED
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
> outa=3 outb=4 outc=5 outd=0
|
|
33
33
|
|
|
34
34
|
@param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
|
|
35
|
-
@param [out] insert_cmplib= (NO) Choose YES to insert the package into the
|
|
36
|
-
CMPLIB reference.
|
|
37
35
|
@param [out] lib= (work) The output library in which to create the catalog.
|
|
38
36
|
@param [out] cat= (sasjs) The output catalog in which to create the package.
|
|
39
37
|
@param [out] pkg= (utils) The output package in which to create the function.
|
|
40
38
|
Uses a 3 part format: libref.catalog.package
|
|
39
|
+
@param [out] insert_cmplib= DEPRECATED - The CMPLIB option is checked and
|
|
40
|
+
values inserted only if needed.
|
|
41
41
|
|
|
42
42
|
<h4> SAS Macros </h4>
|
|
43
43
|
@li mcf_init.sas
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
**/
|
|
50
50
|
|
|
51
51
|
%macro mcf_length(wrap=NO
|
|
52
|
-
,insert_cmplib=
|
|
52
|
+
,insert_cmplib=DEPRECATED
|
|
53
53
|
,lib=WORK
|
|
54
54
|
,cat=SASJS
|
|
55
55
|
,pkg=UTILS
|
|
56
56
|
)/*/STORE SOURCE*/;
|
|
57
|
-
|
|
57
|
+
%local i var cmpval found;
|
|
58
58
|
%if %mcf_init(mcf_length)=1 %then %return;
|
|
59
59
|
|
|
60
60
|
%if &wrap=YES %then %do;
|
|
@@ -76,7 +76,14 @@ endsub;
|
|
|
76
76
|
quit;
|
|
77
77
|
%end;
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
/* insert the CMPLIB if not already there */
|
|
80
|
+
%let cmpval=%sysfunc(getoption(cmplib));
|
|
81
|
+
%let found=0;
|
|
82
|
+
%do i=1 %to %sysfunc(countw(&cmpval,%str( %(%))));
|
|
83
|
+
%let var=%scan(&cmpval,&i,%str( %(%)));
|
|
84
|
+
%if &var=&lib..&cat %then %let found=1;
|
|
85
|
+
%end;
|
|
86
|
+
%if &found=0 %then %do;
|
|
80
87
|
options insert=(CMPLIB=(&lib..&cat));
|
|
81
88
|
%end;
|
|
82
89
|
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
@param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
|
|
50
|
-
@param [out] insert_cmplib= (NO) Choose YES to insert the package into the
|
|
51
|
-
CMPLIB reference.
|
|
52
50
|
@param [out] lib= (work) The output library in which to create the catalog.
|
|
53
51
|
@param [out] cat= (sasjs) The output catalog in which to create the package.
|
|
54
52
|
@param [out] pkg= (utils) The output package in which to create the function.
|
|
55
53
|
Uses a 3 part format: libref.catalog.package
|
|
54
|
+
@param [out] insert_cmplib= DEPRECATED - The CMPLIB option is checked and
|
|
55
|
+
values inserted only if needed.
|
|
56
56
|
|
|
57
57
|
<h4> SAS Macros </h4>
|
|
58
58
|
@li mcf_init.sas
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
**/
|
|
65
65
|
|
|
66
66
|
%macro mcf_stpsrv_header(wrap=NO
|
|
67
|
-
,insert_cmplib=
|
|
67
|
+
,insert_cmplib=DEPRECATED
|
|
68
68
|
,lib=WORK
|
|
69
69
|
,cat=SASJS
|
|
70
70
|
,pkg=UTILS
|
|
71
71
|
)/*/STORE SOURCE*/;
|
|
72
|
-
|
|
72
|
+
%local i var cmpval found;
|
|
73
73
|
%if %mcf_init(stpsrv_header)=1 %then %return;
|
|
74
74
|
|
|
75
75
|
%if &wrap=YES %then %do;
|
|
@@ -96,7 +96,14 @@ endsub;
|
|
|
96
96
|
quit;
|
|
97
97
|
%end;
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
/* insert the CMPLIB if not already there */
|
|
100
|
+
%let cmpval=%sysfunc(getoption(cmplib));
|
|
101
|
+
%let found=0;
|
|
102
|
+
%do i=1 %to %sysfunc(countw(&cmpval,%str( %(%))));
|
|
103
|
+
%let var=%scan(&cmpval,&i,%str( %(%)));
|
|
104
|
+
%if &var=&lib..&cat %then %let found=1;
|
|
105
|
+
%end;
|
|
106
|
+
%if &found=0 %then %do;
|
|
100
107
|
options insert=(CMPLIB=(&lib..&cat));
|
|
101
108
|
%end;
|
|
102
109
|
|
package/fcmp/mcf_string2file.sas
CHANGED
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
run;
|
|
33
33
|
|
|
34
34
|
@param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
|
|
35
|
-
@param [out] insert_cmplib= (NO) Choose YES to insert the package into the
|
|
36
|
-
CMPLIB reference.
|
|
37
35
|
@param [out] lib= (work) The output library in which to create the catalog.
|
|
38
36
|
@param [out] cat= (sasjs) The output catalog in which to create the package.
|
|
39
37
|
@param [out] pkg= (utils) The output package in which to create the function.
|
|
40
38
|
Uses a 3 part format: libref.catalog.package
|
|
39
|
+
@param [out] insert_cmplib= DEPRECATED - The CMPLIB option is checked and
|
|
40
|
+
values inserted only if needed.
|
|
41
41
|
|
|
42
42
|
<h4> SAS Macros </h4>
|
|
43
43
|
@li mcf_init.sas
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
**/
|
|
50
50
|
|
|
51
51
|
%macro mcf_string2file(wrap=NO
|
|
52
|
-
,insert_cmplib=
|
|
52
|
+
,insert_cmplib=DEPRECATED
|
|
53
53
|
,lib=WORK
|
|
54
54
|
,cat=SASJS
|
|
55
55
|
,pkg=UTILS
|
|
56
56
|
)/*/STORE SOURCE*/;
|
|
57
|
-
|
|
57
|
+
%local i var cmpval found;
|
|
58
58
|
%if %mcf_init(mcf_string2file)=1 %then %return;
|
|
59
59
|
|
|
60
60
|
%if &wrap=YES %then %do;
|
|
@@ -81,7 +81,14 @@ endsub;
|
|
|
81
81
|
quit;
|
|
82
82
|
%end;
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
/* insert the CMPLIB if not already there */
|
|
85
|
+
%let cmpval=%sysfunc(getoption(cmplib));
|
|
86
|
+
%let found=0;
|
|
87
|
+
%do i=1 %to %sysfunc(countw(&cmpval,%str( %(%))));
|
|
88
|
+
%let var=%scan(&cmpval,&i,%str( %(%)));
|
|
89
|
+
%if &var=&lib..&cat %then %let found=1;
|
|
90
|
+
%end;
|
|
91
|
+
%if &found=0 %then %do;
|
|
85
92
|
options insert=(CMPLIB=(&lib..&cat));
|
|
86
93
|
%end;
|
|
87
94
|
|
package/package.json
CHANGED