@sasjs/core 3.7.5 → 3.8.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.
- package/README.md +7 -0
- package/base/mp_jsonout.sas +28 -13
- package/meta/mm_createwebservice.sas +20 -4
- package/meta/mm_webout.sas +9 -7
- package/package.json +1 -1
- package/server/ms_webout.sas +9 -7
- package/viya/mv_createwebservice.sas +20 -4
- package/viya/mv_webout.sas +11 -9
package/README.md
CHANGED
|
@@ -188,6 +188,13 @@ When contributing to this library, it is therefore important to ensure that all
|
|
|
188
188
|
|
|
189
189
|
- All macros should be compatible with SAS versions from support level B and above (so currently 9.2 and later). If an earlier version is not supported, then the macro should say as such in the header documentation, and exit gracefully (eg `%if %sysevalf(&sysver<9.3) %then %return`).
|
|
190
190
|
|
|
191
|
+
## Breaking Changes
|
|
192
|
+
|
|
193
|
+
We are currently on major release v3. The following changes are planned when the next major (breaking) release becomes necessary:
|
|
194
|
+
|
|
195
|
+
* Remove `dbg` parameter from mp_jsonout.sas (implement mdebug instead)
|
|
196
|
+
* Remove `END_DTTM` and `START_DTTM` from mx_webout JSON
|
|
197
|
+
|
|
191
198
|
## Star Gazing
|
|
192
199
|
|
|
193
200
|
If you find this library useful, please leave a [star](https://github.com/sasjs/core/stargazers) and help us grow our star graph!
|
package/base/mp_jsonout.sas
CHANGED
|
@@ -31,22 +31,20 @@
|
|
|
31
31
|
[sasjs adapter](https://github.com/sasjs/adapter).
|
|
32
32
|
For more information see https://sasjs.io
|
|
33
33
|
|
|
34
|
-
@param action Valid values:
|
|
34
|
+
@param [in] action Valid values:
|
|
35
35
|
@li OPEN - opens the JSON
|
|
36
36
|
@li OBJ - sends a table with each row as an object
|
|
37
37
|
@li ARR - sends a table with each row in an array
|
|
38
38
|
@li CLOSE - closes the JSON
|
|
39
|
-
|
|
40
|
-
@param
|
|
41
|
-
@param
|
|
42
|
-
@param
|
|
43
|
-
@param
|
|
44
|
-
@param engine= Which engine to use to send the JSON, valid options are:
|
|
39
|
+
@param [in] ds The dataset to send. Must be a work table.
|
|
40
|
+
@param [out] jref= (_webout) The fileref to which to send the JSON
|
|
41
|
+
@param [out] dslabel= The name to give the table in the exported JSON
|
|
42
|
+
@param [in] fmt= (Y) Whether to keep (Y) or strip (N) formats from the table
|
|
43
|
+
@param [in] engine= (DATASTEP) Which engine to use to send the JSON. Options:
|
|
45
44
|
@li PROCJSON (default)
|
|
46
45
|
@li DATASTEP (more reliable when data has non standard characters)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
proc json but this can cause line truncation in large files.
|
|
46
|
+
@param [in] missing= (NULL) Special numeric missing values can be sent as NULL
|
|
47
|
+
(eg `null`) or as STRING values (eg `".a"` or `".b"`)
|
|
50
48
|
|
|
51
49
|
<h4> Related Macros <h4>
|
|
52
50
|
@li mp_ds2fmtds.sas
|
|
@@ -57,9 +55,11 @@
|
|
|
57
55
|
|
|
58
56
|
**/
|
|
59
57
|
|
|
60
|
-
%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y,engine=DATASTEP
|
|
58
|
+
%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y,engine=DATASTEP
|
|
59
|
+
,dbg=0 /* DEPRECATED */
|
|
60
|
+
,missing=NULL
|
|
61
61
|
)/*/STORE SOURCE*/;
|
|
62
|
-
%put output location=&jref;
|
|
62
|
+
%put &sysmacroname: output location=&jref;
|
|
63
63
|
%if &action=OPEN %then %do;
|
|
64
64
|
options nobomfile;
|
|
65
65
|
data _null_;file &jref encoding='utf-8' ;
|
|
@@ -72,10 +72,16 @@
|
|
|
72
72
|
put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":";
|
|
73
73
|
|
|
74
74
|
%if &engine=PROCJSON %then %do;
|
|
75
|
+
%if &missing=STRING %then %do;
|
|
76
|
+
%put &sysmacroname: Special Missings are not supported in proc json.;
|
|
77
|
+
%put &sysmacroname: Switching to DATASTEP engine;
|
|
78
|
+
%goto datastep;
|
|
79
|
+
%end;
|
|
75
80
|
data;run;%let tempds=&syslast;
|
|
76
81
|
proc sql;drop table &tempds;
|
|
77
82
|
data &tempds /view=&tempds;set &ds;
|
|
78
83
|
%if &fmt=N %then format _numeric_ best32.;;
|
|
84
|
+
/* PRETTY is necessary to avoid line truncation in large files */
|
|
79
85
|
proc json out=&jref pretty
|
|
80
86
|
%if &action=ARR %then nokeys ;
|
|
81
87
|
;export &tempds / nosastags fmtnumeric;
|
|
@@ -83,6 +89,7 @@
|
|
|
83
89
|
proc sql;drop view &tempds;
|
|
84
90
|
%end;
|
|
85
91
|
%else %if &engine=DATASTEP %then %do;
|
|
92
|
+
%datastep:
|
|
86
93
|
%local cols i tempds;
|
|
87
94
|
%let cols=0;
|
|
88
95
|
%if %sysfunc(exist(&ds)) ne 1 & %sysfunc(exist(&ds,VIEW)) ne 1 %then %do;
|
|
@@ -163,7 +170,15 @@
|
|
|
163
170
|
run;
|
|
164
171
|
|
|
165
172
|
proc format; /* credit yabwon for special null removal */
|
|
166
|
-
|
|
173
|
+
value bart
|
|
174
|
+
%if &missing=NULL %then %do;
|
|
175
|
+
._ - .z = null
|
|
176
|
+
%end;
|
|
177
|
+
%else %do;
|
|
178
|
+
._ = [quote()]
|
|
179
|
+
. = null
|
|
180
|
+
.a - .z = [quote()]
|
|
181
|
+
%end;
|
|
167
182
|
other = [best.];
|
|
168
183
|
|
|
169
184
|
data;run; %let tempds=&syslast; /* temp table for spesh char management */
|
|
@@ -90,8 +90,9 @@ data _null_;
|
|
|
90
90
|
/* WEBOUT BEGIN */
|
|
91
91
|
put ' ';
|
|
92
92
|
put '%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y,engine=DATASTEP,dbg=0 ';
|
|
93
|
+
put ' ,missing=NULL ';
|
|
93
94
|
put ')/*/STORE SOURCE*/; ';
|
|
94
|
-
put '%put output location=&jref; ';
|
|
95
|
+
put '%put &sysmacroname: output location=&jref; ';
|
|
95
96
|
put '%if &action=OPEN %then %do; ';
|
|
96
97
|
put ' options nobomfile; ';
|
|
97
98
|
put ' data _null_;file &jref encoding=''utf-8'' ; ';
|
|
@@ -104,10 +105,16 @@ data _null_;
|
|
|
104
105
|
put ' put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":"; ';
|
|
105
106
|
put ' ';
|
|
106
107
|
put ' %if &engine=PROCJSON %then %do; ';
|
|
108
|
+
put ' %if &missing=STRING %then %do; ';
|
|
109
|
+
put ' %put &sysmacroname: Special Missings are not supported in proc json.; ';
|
|
110
|
+
put ' %put &sysmacroname: Switching to DATASTEP engine; ';
|
|
111
|
+
put ' %goto datastep; ';
|
|
112
|
+
put ' %end; ';
|
|
107
113
|
put ' data;run;%let tempds=&syslast; ';
|
|
108
114
|
put ' proc sql;drop table &tempds; ';
|
|
109
115
|
put ' data &tempds /view=&tempds;set &ds; ';
|
|
110
116
|
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
|
117
|
+
put ' /* PRETTY is necessary to avoid line truncation in large files */ ';
|
|
111
118
|
put ' proc json out=&jref pretty ';
|
|
112
119
|
put ' %if &action=ARR %then nokeys ; ';
|
|
113
120
|
put ' ;export &tempds / nosastags fmtnumeric; ';
|
|
@@ -115,6 +122,7 @@ data _null_;
|
|
|
115
122
|
put ' proc sql;drop view &tempds; ';
|
|
116
123
|
put ' %end; ';
|
|
117
124
|
put ' %else %if &engine=DATASTEP %then %do; ';
|
|
125
|
+
put ' %datastep: ';
|
|
118
126
|
put ' %local cols i tempds; ';
|
|
119
127
|
put ' %let cols=0; ';
|
|
120
128
|
put ' %if %sysfunc(exist(&ds)) ne 1 & %sysfunc(exist(&ds,VIEW)) ne 1 %then %do; ';
|
|
@@ -195,7 +203,15 @@ data _null_;
|
|
|
195
203
|
put ' run; ';
|
|
196
204
|
put ' ';
|
|
197
205
|
put ' proc format; /* credit yabwon for special null removal */ ';
|
|
198
|
-
put '
|
|
206
|
+
put ' value bart ';
|
|
207
|
+
put ' %if &missing=NULL %then %do; ';
|
|
208
|
+
put ' ._ - .z = null ';
|
|
209
|
+
put ' %end; ';
|
|
210
|
+
put ' %else %do; ';
|
|
211
|
+
put ' ._ = [quote()] ';
|
|
212
|
+
put ' . = null ';
|
|
213
|
+
put ' .a - .z = [quote()] ';
|
|
214
|
+
put ' %end; ';
|
|
199
215
|
put ' other = [best.]; ';
|
|
200
216
|
put ' ';
|
|
201
217
|
put ' data;run; %let tempds=&syslast; /* temp table for spesh char management */ ';
|
|
@@ -263,7 +279,7 @@ data _null_;
|
|
|
263
279
|
put ' run; ';
|
|
264
280
|
put '%end; ';
|
|
265
281
|
put '%mend mp_jsonout; ';
|
|
266
|
-
put '%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y); ';
|
|
282
|
+
put '%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y,missing=NULL); ';
|
|
267
283
|
put '%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug ';
|
|
268
284
|
put ' sasjs_tables; ';
|
|
269
285
|
put '%local i tempds jsonengine; ';
|
|
@@ -328,7 +344,7 @@ data _null_;
|
|
|
328
344
|
put ' ';
|
|
329
345
|
put '%else %if &action=ARR or &action=OBJ %then %do; ';
|
|
330
346
|
put ' %mp_jsonout(&action,&ds,dslabel=&dslabel,fmt=&fmt,jref=&fref ';
|
|
331
|
-
put ' ,engine=&jsonengine,
|
|
347
|
+
put ' ,engine=&jsonengine,missing=&missing ';
|
|
332
348
|
put ' ) ';
|
|
333
349
|
put '%end; ';
|
|
334
350
|
put '%else %if &action=CLOSE %then %do; ';
|
package/meta/mm_webout.sas
CHANGED
|
@@ -23,17 +23,19 @@
|
|
|
23
23
|
%mm_webout(CLOSE)
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
@param action Either FETCH, OPEN, ARR, OBJ or CLOSE
|
|
27
|
-
@param ds The dataset to send back to the frontend
|
|
28
|
-
@param dslabel=
|
|
29
|
-
@param fmt=(Y) Set to N to send back unformatted values
|
|
30
|
-
@param fref=(_webout) The fileref to which to write the JSON
|
|
26
|
+
@param [in] action Either FETCH, OPEN, ARR, OBJ or CLOSE
|
|
27
|
+
@param [in] ds The dataset to send back to the frontend
|
|
28
|
+
@param [out] dslabel= Value to use instead of table name for sending to JSON
|
|
29
|
+
@param [in] fmt=(Y) Set to N to send back unformatted values
|
|
30
|
+
@param [out] fref= (_webout) The fileref to which to write the JSON
|
|
31
|
+
@param [in] missing= (NULL) Special numeric missing values can be sent as NULL
|
|
32
|
+
(eg `null`) or as STRING values (eg `".a"` or `".b"`)
|
|
31
33
|
|
|
32
34
|
@version 9.3
|
|
33
35
|
@author Allan Bowe
|
|
34
36
|
|
|
35
37
|
**/
|
|
36
|
-
%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y);
|
|
38
|
+
%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y,missing=NULL);
|
|
37
39
|
%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug
|
|
38
40
|
sasjs_tables;
|
|
39
41
|
%local i tempds jsonengine;
|
|
@@ -98,7 +100,7 @@
|
|
|
98
100
|
|
|
99
101
|
%else %if &action=ARR or &action=OBJ %then %do;
|
|
100
102
|
%mp_jsonout(&action,&ds,dslabel=&dslabel,fmt=&fmt,jref=&fref
|
|
101
|
-
,engine=&jsonengine,
|
|
103
|
+
,engine=&jsonengine,missing=&missing
|
|
102
104
|
)
|
|
103
105
|
%end;
|
|
104
106
|
%else %if &action=CLOSE %then %do;
|
package/package.json
CHANGED
package/server/ms_webout.sas
CHANGED
|
@@ -20,11 +20,13 @@
|
|
|
20
20
|
%ms_webout(CLOSE)
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
@param action Either FETCH, OPEN, ARR, OBJ or CLOSE
|
|
24
|
-
@param ds The dataset to send back to the frontend
|
|
25
|
-
@param dslabel= value to use instead of
|
|
26
|
-
@param fmt=(Y) Set to N to send back unformatted values
|
|
27
|
-
@param fref=(_webout) The fileref to which to write the JSON
|
|
23
|
+
@param [in] action Either FETCH, OPEN, ARR, OBJ or CLOSE
|
|
24
|
+
@param [in] ds The dataset to send back to the frontend
|
|
25
|
+
@param [out] dslabel= value to use instead of table name for sending to JSON
|
|
26
|
+
@param [in] fmt= (Y) Set to N to send back unformatted values
|
|
27
|
+
@param [out] fref= (_webout) The fileref to which to write the JSON
|
|
28
|
+
@param [in] missing= (NULL) Special numeric missing values can be sent as NULL
|
|
29
|
+
(eg `null`) or as STRING values (eg `".a"` or `".b"`)
|
|
28
30
|
|
|
29
31
|
<h4> SAS Macros </h4>
|
|
30
32
|
@li mp_jsonout.sas
|
|
@@ -39,7 +41,7 @@
|
|
|
39
41
|
|
|
40
42
|
**/
|
|
41
43
|
|
|
42
|
-
%macro ms_webout(action,ds,dslabel=,fref=_webout,fmt=Y);
|
|
44
|
+
%macro ms_webout(action,ds,dslabel=,fref=_webout,fmt=Y,missing=NULL);
|
|
43
45
|
%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug
|
|
44
46
|
sasjs_tables;
|
|
45
47
|
|
|
@@ -91,7 +93,7 @@
|
|
|
91
93
|
|
|
92
94
|
%else %if &action=ARR or &action=OBJ %then %do;
|
|
93
95
|
%mp_jsonout(&action,&ds,dslabel=&dslabel,fmt=&fmt,jref=&fref
|
|
94
|
-
,engine=DATASTEP,
|
|
96
|
+
,engine=DATASTEP,missing=&missing
|
|
95
97
|
)
|
|
96
98
|
%end;
|
|
97
99
|
%else %if &action=CLOSE %then %do;
|
|
@@ -238,8 +238,9 @@ data _null_;
|
|
|
238
238
|
/* WEBOUT BEGIN */
|
|
239
239
|
put ' ';
|
|
240
240
|
put '%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y,engine=DATASTEP,dbg=0 ';
|
|
241
|
+
put ' ,missing=NULL ';
|
|
241
242
|
put ')/*/STORE SOURCE*/; ';
|
|
242
|
-
put '%put output location=&jref; ';
|
|
243
|
+
put '%put &sysmacroname: output location=&jref; ';
|
|
243
244
|
put '%if &action=OPEN %then %do; ';
|
|
244
245
|
put ' options nobomfile; ';
|
|
245
246
|
put ' data _null_;file &jref encoding=''utf-8'' ; ';
|
|
@@ -252,10 +253,16 @@ data _null_;
|
|
|
252
253
|
put ' put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":"; ';
|
|
253
254
|
put ' ';
|
|
254
255
|
put ' %if &engine=PROCJSON %then %do; ';
|
|
256
|
+
put ' %if &missing=STRING %then %do; ';
|
|
257
|
+
put ' %put &sysmacroname: Special Missings are not supported in proc json.; ';
|
|
258
|
+
put ' %put &sysmacroname: Switching to DATASTEP engine; ';
|
|
259
|
+
put ' %goto datastep; ';
|
|
260
|
+
put ' %end; ';
|
|
255
261
|
put ' data;run;%let tempds=&syslast; ';
|
|
256
262
|
put ' proc sql;drop table &tempds; ';
|
|
257
263
|
put ' data &tempds /view=&tempds;set &ds; ';
|
|
258
264
|
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
|
265
|
+
put ' /* PRETTY is necessary to avoid line truncation in large files */ ';
|
|
259
266
|
put ' proc json out=&jref pretty ';
|
|
260
267
|
put ' %if &action=ARR %then nokeys ; ';
|
|
261
268
|
put ' ;export &tempds / nosastags fmtnumeric; ';
|
|
@@ -263,6 +270,7 @@ data _null_;
|
|
|
263
270
|
put ' proc sql;drop view &tempds; ';
|
|
264
271
|
put ' %end; ';
|
|
265
272
|
put ' %else %if &engine=DATASTEP %then %do; ';
|
|
273
|
+
put ' %datastep: ';
|
|
266
274
|
put ' %local cols i tempds; ';
|
|
267
275
|
put ' %let cols=0; ';
|
|
268
276
|
put ' %if %sysfunc(exist(&ds)) ne 1 & %sysfunc(exist(&ds,VIEW)) ne 1 %then %do; ';
|
|
@@ -343,7 +351,15 @@ data _null_;
|
|
|
343
351
|
put ' run; ';
|
|
344
352
|
put ' ';
|
|
345
353
|
put ' proc format; /* credit yabwon for special null removal */ ';
|
|
346
|
-
put '
|
|
354
|
+
put ' value bart ';
|
|
355
|
+
put ' %if &missing=NULL %then %do; ';
|
|
356
|
+
put ' ._ - .z = null ';
|
|
357
|
+
put ' %end; ';
|
|
358
|
+
put ' %else %do; ';
|
|
359
|
+
put ' ._ = [quote()] ';
|
|
360
|
+
put ' . = null ';
|
|
361
|
+
put ' .a - .z = [quote()] ';
|
|
362
|
+
put ' %end; ';
|
|
347
363
|
put ' other = [best.]; ';
|
|
348
364
|
put ' ';
|
|
349
365
|
put ' data;run; %let tempds=&syslast; /* temp table for spesh char management */ ';
|
|
@@ -411,7 +427,7 @@ data _null_;
|
|
|
411
427
|
put ' run; ';
|
|
412
428
|
put '%end; ';
|
|
413
429
|
put '%mend mp_jsonout; ';
|
|
414
|
-
put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y); ';
|
|
430
|
+
put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y,missing=NULL); ';
|
|
415
431
|
put '%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name ';
|
|
416
432
|
put ' sasjs_tables SYS_JES_JOB_URI; ';
|
|
417
433
|
put '%if %index("&_debug",log) %then %let _debug=131; ';
|
|
@@ -538,7 +554,7 @@ data _null_;
|
|
|
538
554
|
put '%end; ';
|
|
539
555
|
put '%else %if &action=ARR or &action=OBJ %then %do; ';
|
|
540
556
|
put ' %mp_jsonout(&action,&ds,dslabel=&dslabel,fmt=&fmt ';
|
|
541
|
-
put ' ,jref=&fref,engine=DATASTEP,
|
|
557
|
+
put ' ,jref=&fref,engine=DATASTEP,missing=&missing ';
|
|
542
558
|
put ' ) ';
|
|
543
559
|
put '%end; ';
|
|
544
560
|
put '%else %if &action=CLOSE %then %do; ';
|
package/viya/mv_webout.sas
CHANGED
|
@@ -20,13 +20,15 @@
|
|
|
20
20
|
%mv_webout(CLOSE)
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
@param action Either OPEN, ARR, OBJ or CLOSE
|
|
24
|
-
@param ds The dataset to send back to the frontend
|
|
25
|
-
@param _webout= fileref for returning the json
|
|
26
|
-
@param fref=(_mvwtemp) Temp fileref to which to write the output
|
|
27
|
-
@param dslabel= value to use instead of
|
|
28
|
-
@param fmt=(Y) change to N to strip formats from output
|
|
29
|
-
@param stream=(Y) Change to N if not streaming to _webout
|
|
23
|
+
@param [in] action Either OPEN, ARR, OBJ or CLOSE
|
|
24
|
+
@param [in] ds The dataset to send back to the frontend
|
|
25
|
+
@param [in] _webout= fileref for returning the json
|
|
26
|
+
@param [out] fref=(_mvwtemp) Temp fileref to which to write the output
|
|
27
|
+
@param [out] dslabel= value to use instead of table name for sending to JSON
|
|
28
|
+
@param [in] fmt=(Y) change to N to strip formats from output
|
|
29
|
+
@param [in] stream=(Y) Change to N if not streaming to _webout
|
|
30
|
+
@param [in] missing= (NULL) Special numeric missing values can be sent as NULL
|
|
31
|
+
(eg `null`) or as STRING values (eg `".a"` or `".b"`)
|
|
30
32
|
|
|
31
33
|
<h4> SAS Macros </h4>
|
|
32
34
|
@li mp_jsonout.sas
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
@author Allan Bowe, source: https://github.com/sasjs/core
|
|
37
39
|
|
|
38
40
|
**/
|
|
39
|
-
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y);
|
|
41
|
+
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y,missing=NULL);
|
|
40
42
|
%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name
|
|
41
43
|
sasjs_tables SYS_JES_JOB_URI;
|
|
42
44
|
%if %index("&_debug",log) %then %let _debug=131;
|
|
@@ -163,7 +165,7 @@
|
|
|
163
165
|
%end;
|
|
164
166
|
%else %if &action=ARR or &action=OBJ %then %do;
|
|
165
167
|
%mp_jsonout(&action,&ds,dslabel=&dslabel,fmt=&fmt
|
|
166
|
-
,jref=&fref,engine=DATASTEP,
|
|
168
|
+
,jref=&fref,engine=DATASTEP,missing=&missing
|
|
167
169
|
)
|
|
168
170
|
%end;
|
|
169
171
|
%else %if &action=CLOSE %then %do;
|