@sasjs/core 4.32.0 → 4.32.3
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/base/mp_abort.sas +7 -4
- package/base/mp_binarycopy.sas +12 -22
- package/base/mp_jsonout.sas +63 -24
- package/meta/mm_createfolder.sas +1 -1
- package/meta/mm_createwebservice.sas +75 -34
- package/meta/mm_webout.sas +34 -18
- package/package.json +1 -1
- package/server/ms_createwebservice.sas +53 -23
- package/viya/mv_createwebservice.sas +53 -23
package/base/mp_abort.sas
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
The method used varies according to the context. Important points:
|
|
10
10
|
|
|
11
|
-
@li should not use endsas or abort cancel in 9.4m3 environments as this
|
|
12
|
-
cause hung multibridge sessions and result in a frozen STP server
|
|
11
|
+
@li should not use endsas or abort cancel in 9.4m3 WIN environments as this
|
|
12
|
+
can cause hung multibridge sessions and result in a frozen STP server
|
|
13
|
+
@li The use of endsas in 9.4m6+ windows environments for POST requests to the
|
|
14
|
+
STP server can result in an empty response body
|
|
13
15
|
@li should not use endsas in viya 3.5 as this destroys the session and cannot
|
|
14
16
|
fetch results (although both mv_getjoblog.sas and the @sasjs/adapter will
|
|
15
17
|
recognise this and fetch the log of the parent session instead)
|
|
@@ -21,8 +23,8 @@
|
|
|
21
23
|
a macro. For that, we recommend you use mp_include.sas to perform the
|
|
22
24
|
include, and then call \%mp_abort(mode=INCLUDE) from the source program (ie,
|
|
23
25
|
OUTSIDE of the top-parent macro).
|
|
24
|
-
The soft abort has
|
|
25
|
-
|
|
26
|
+
The soft abort has become ineffective in 9.4m6 WINDOWS environments. We are
|
|
27
|
+
currently investigating approaches to deal with this.
|
|
26
28
|
|
|
27
29
|
|
|
28
30
|
@param mac= (mp_abort.sas) To contain the name of the calling macro. Do not
|
|
@@ -247,6 +249,7 @@ and %superq(SYSPROCESSNAME) ne %str(Compute Server)
|
|
|
247
249
|
call symputx("syscc",0,"g");
|
|
248
250
|
run;
|
|
249
251
|
%if &sysscp=WIN
|
|
252
|
+
and 1=0 /* deprecating this logic until we figure out a consistent abort */
|
|
250
253
|
and "%substr(%str(&sysvlong ),1,8)"="9.04.01M"
|
|
251
254
|
and "%substr(%str(&sysvlong ),9,1)">"5" %then %do;
|
|
252
255
|
/* skip approach (below) does not work in windows m6+ envs */
|
package/base/mp_binarycopy.sas
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
@details Reads in a file byte by byte and writes it back out. Is an
|
|
5
5
|
os-independent method to copy files. In case of naming collision, the
|
|
6
6
|
default filerefs can be modified.
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
Note that if you have a new enough version of SAS, and you don't need features
|
|
8
|
+
such as APPEND, you may be better of using the fcopy() function instead.
|
|
9
9
|
|
|
10
10
|
%mp_binarycopy(inloc="/home/me/blah.txt", outref=_webout)
|
|
11
11
|
|
|
@@ -45,14 +45,9 @@
|
|
|
45
45
|
,outref=____out /* override default to use own filerefs */
|
|
46
46
|
,mode=CREATE
|
|
47
47
|
)/*/STORE SOURCE*/;
|
|
48
|
-
%local mod
|
|
49
|
-
%if &mode=APPEND %then %
|
|
50
|
-
|
|
51
|
-
%let outmode='a';
|
|
52
|
-
%end;
|
|
53
|
-
%else %do;
|
|
54
|
-
%let outmode='o';
|
|
55
|
-
%end;
|
|
48
|
+
%local mod;
|
|
49
|
+
%if &mode=APPEND %then %let mod=mod;
|
|
50
|
+
|
|
56
51
|
/* these IN and OUT filerefs can point to anything */
|
|
57
52
|
%if &inref = ____in %then %do;
|
|
58
53
|
filename &inref &inloc lrecl=1048576 ;
|
|
@@ -63,22 +58,17 @@
|
|
|
63
58
|
|
|
64
59
|
/* copy the file byte-for-byte */
|
|
65
60
|
data _null_;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
rc = fget(filein,rec,1);
|
|
72
|
-
rc = fput(fileid, rec);
|
|
73
|
-
rc =fwrite(fileid);
|
|
74
|
-
end;
|
|
75
|
-
rc = fclose(filein);
|
|
76
|
-
rc = fclose(fileid);
|
|
61
|
+
infile &inref lrecl=1 recfm=n;
|
|
62
|
+
file &outref &mod recfm=n;
|
|
63
|
+
input sourcechar $char1. @@;
|
|
64
|
+
format sourcechar hex2.;
|
|
65
|
+
put sourcechar char1. @@;
|
|
77
66
|
run;
|
|
67
|
+
|
|
78
68
|
%if &inref = ____in %then %do;
|
|
79
69
|
filename &inref clear;
|
|
80
70
|
%end;
|
|
81
71
|
%if &outref=____out %then %do;
|
|
82
72
|
filename &outref clear;
|
|
83
73
|
%end;
|
|
84
|
-
%mend mp_binarycopy;
|
|
74
|
+
%mend mp_binarycopy;
|
package/base/mp_jsonout.sas
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
@file mp_jsonout.sas
|
|
3
3
|
@brief Writes JSON in SASjs format to a fileref
|
|
4
|
-
@details
|
|
4
|
+
@details This macro can be used to OPEN a JSON stream and send one or more
|
|
5
|
+
tables as arrays of rows, where each row can be an object or a nested array.
|
|
6
|
+
|
|
7
|
+
There are two engines available - DATASTEP or PROCJSON.
|
|
8
|
+
|
|
9
|
+
PROC JSON is fast but will produce errs like the ones below if
|
|
5
10
|
special chars are encountered.
|
|
6
11
|
|
|
7
12
|
> (ERR)OR: Some code points did not transcode.
|
|
@@ -12,6 +17,10 @@
|
|
|
12
17
|
|
|
13
18
|
If this happens, try running with ENGINE=DATASTEP.
|
|
14
19
|
|
|
20
|
+
The DATASTEP engine is used to handle special SAS missing numerics, and
|
|
21
|
+
can also convert entire datasets to formatted values. Output JSON is always
|
|
22
|
+
in UTF-8.
|
|
23
|
+
|
|
15
24
|
Usage:
|
|
16
25
|
|
|
17
26
|
filename tmp temp;
|
|
@@ -75,9 +84,23 @@
|
|
|
75
84
|
run;
|
|
76
85
|
%end;
|
|
77
86
|
%else %if (&action=ARR or &action=OBJ) %then %do;
|
|
87
|
+
/* force variable names to always be uppercase in the JSON */
|
|
78
88
|
options validvarname=upcase;
|
|
79
|
-
|
|
89
|
+
/* To avoid issues with _webout on EBI - such as encoding diffs and truncation
|
|
90
|
+
(https://support.sas.com/kb/49/325.html) we use temporary files */
|
|
91
|
+
filename _sjs1 temp lrecl=200 ;
|
|
92
|
+
data _null_; file _sjs1 encoding='utf-8';
|
|
80
93
|
put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":";
|
|
94
|
+
run;
|
|
95
|
+
/* now write to _webout 1 char at a time */
|
|
96
|
+
data _null_;
|
|
97
|
+
infile _sjs1 lrecl=1 recfm=n;
|
|
98
|
+
file &jref mod lrecl=1 recfm=n;
|
|
99
|
+
input sourcechar $char1. @@;
|
|
100
|
+
format sourcechar hex2.;
|
|
101
|
+
put sourcechar char1. @@;
|
|
102
|
+
run;
|
|
103
|
+
filename _sjs1 clear;
|
|
81
104
|
|
|
82
105
|
/* grab col defs */
|
|
83
106
|
proc contents noprint data=&ds
|
|
@@ -134,10 +157,20 @@
|
|
|
134
157
|
data &tempds;set &ds;
|
|
135
158
|
%if &fmt=N %then format _numeric_ best32.;;
|
|
136
159
|
/* PRETTY is necessary to avoid line truncation in large files */
|
|
137
|
-
|
|
160
|
+
filename _sjs2 temp lrecl=131068 encoding='utf-8';
|
|
161
|
+
proc json out=_sjs2 pretty
|
|
138
162
|
%if &action=ARR %then nokeys ;
|
|
139
163
|
;export &tempds / nosastags fmtnumeric;
|
|
140
164
|
run;
|
|
165
|
+
/* send back to webout */
|
|
166
|
+
data _null_;
|
|
167
|
+
infile _sjs2 lrecl=1 recfm=n;
|
|
168
|
+
file &jref mod lrecl=1 recfm=n;
|
|
169
|
+
input sourcechar $char1. @@;
|
|
170
|
+
format sourcechar hex2.;
|
|
171
|
+
put sourcechar char1. @@;
|
|
172
|
+
run;
|
|
173
|
+
filename _sjs2 clear;
|
|
141
174
|
%end;
|
|
142
175
|
%else %if &engine=DATASTEP %then %do;
|
|
143
176
|
%datastep:
|
|
@@ -220,10 +253,9 @@
|
|
|
220
253
|
%end;
|
|
221
254
|
run;
|
|
222
255
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
data _null_; file _sjs lrecl=131068 encoding='utf-8' mod ;
|
|
256
|
+
filename _sjs3 temp lrecl=131068 ;
|
|
257
|
+
data _null_;
|
|
258
|
+
file _sjs3 encoding='utf-8';
|
|
227
259
|
if _n_=1 then put "[";
|
|
228
260
|
set &tempds;
|
|
229
261
|
if _n_>1 then put "," @; put
|
|
@@ -234,31 +266,29 @@
|
|
|
234
266
|
"&&name&i"n /* name literal for reserved variable names */
|
|
235
267
|
%end;
|
|
236
268
|
%if &action=ARR %then "]" ; %else "}" ; ;
|
|
237
|
-
|
|
269
|
+
|
|
270
|
+
/* close out the table */
|
|
238
271
|
data _null_;
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
/* close out the table */
|
|
249
|
-
rc=fput(fileid, "]");
|
|
250
|
-
rc=fwrite(fileid);
|
|
251
|
-
rc=fclose(filein);
|
|
252
|
-
rc=fclose(fileid);
|
|
272
|
+
file _sjs3 mod encoding='utf-8';
|
|
273
|
+
put ']';
|
|
274
|
+
run;
|
|
275
|
+
data _null_;
|
|
276
|
+
infile _sjs3 lrecl=1 recfm=n;
|
|
277
|
+
file &jref mod lrecl=1 recfm=n;
|
|
278
|
+
input sourcechar $char1. @@;
|
|
279
|
+
format sourcechar hex2.;
|
|
280
|
+
put sourcechar char1. @@;
|
|
253
281
|
run;
|
|
254
|
-
filename
|
|
282
|
+
filename _sjs3 clear;
|
|
255
283
|
%end;
|
|
256
284
|
|
|
257
285
|
proc sql;
|
|
258
286
|
drop table &colinfo, &tempds;
|
|
259
287
|
|
|
260
288
|
%if &showmeta=YES %then %do;
|
|
261
|
-
|
|
289
|
+
filename _sjs4 temp lrecl=131068 encoding='utf-8';
|
|
290
|
+
data _null_;
|
|
291
|
+
file _sjs4;
|
|
262
292
|
put ", ""$%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":{""vars"":{";
|
|
263
293
|
do i=1 to &numcols;
|
|
264
294
|
name=quote(trim(symget(cats('name',i))));
|
|
@@ -272,6 +302,15 @@
|
|
|
272
302
|
end;
|
|
273
303
|
put '}}';
|
|
274
304
|
run;
|
|
305
|
+
/* send back to webout */
|
|
306
|
+
data _null_;
|
|
307
|
+
infile _sjs4 lrecl=1 recfm=n;
|
|
308
|
+
file &jref mod lrecl=1 recfm=n;
|
|
309
|
+
input sourcechar $char1. @@;
|
|
310
|
+
format sourcechar hex2.;
|
|
311
|
+
put sourcechar char1. @@;
|
|
312
|
+
run;
|
|
313
|
+
filename _sjs4 clear;
|
|
275
314
|
%end;
|
|
276
315
|
%end;
|
|
277
316
|
|
package/meta/mm_createfolder.sas
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
@file mm_createwebservice.sas
|
|
3
3
|
@brief Create a Web Ready Stored Process
|
|
4
4
|
@details This macro creates a Type 2 Stored Process with the mm_webout macro
|
|
5
|
-
|
|
5
|
+
(and dependencies) included as pre-code.
|
|
6
|
+
|
|
6
7
|
Usage:
|
|
7
8
|
|
|
8
9
|
%* compile macros ;
|
|
@@ -108,9 +109,23 @@ data _null_;
|
|
|
108
109
|
put ' run; ';
|
|
109
110
|
put '%end; ';
|
|
110
111
|
put '%else %if (&action=ARR or &action=OBJ) %then %do; ';
|
|
112
|
+
put ' /* force variable names to always be uppercase in the JSON */ ';
|
|
111
113
|
put ' options validvarname=upcase; ';
|
|
112
|
-
put '
|
|
114
|
+
put ' /* To avoid issues with _webout on EBI - such as encoding diffs and truncation ';
|
|
115
|
+
put ' (https://support.sas.com/kb/49/325.html) we use temporary files */ ';
|
|
116
|
+
put ' filename _sjs1 temp lrecl=200 ; ';
|
|
117
|
+
put ' data _null_; file _sjs1 encoding=''utf-8''; ';
|
|
113
118
|
put ' put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":"; ';
|
|
119
|
+
put ' run; ';
|
|
120
|
+
put ' /* now write to _webout 1 char at a time */ ';
|
|
121
|
+
put ' data _null_; ';
|
|
122
|
+
put ' infile _sjs1 lrecl=1 recfm=n; ';
|
|
123
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
124
|
+
put ' input sourcechar $char1. @@; ';
|
|
125
|
+
put ' format sourcechar hex2.; ';
|
|
126
|
+
put ' put sourcechar char1. @@; ';
|
|
127
|
+
put ' run; ';
|
|
128
|
+
put ' filename _sjs1 clear; ';
|
|
114
129
|
put ' ';
|
|
115
130
|
put ' /* grab col defs */ ';
|
|
116
131
|
put ' proc contents noprint data=&ds ';
|
|
@@ -167,10 +182,20 @@ data _null_;
|
|
|
167
182
|
put ' data &tempds;set &ds; ';
|
|
168
183
|
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
|
169
184
|
put ' /* PRETTY is necessary to avoid line truncation in large files */ ';
|
|
170
|
-
put '
|
|
185
|
+
put ' filename _sjs2 temp lrecl=131068 encoding=''utf-8''; ';
|
|
186
|
+
put ' proc json out=_sjs2 pretty ';
|
|
171
187
|
put ' %if &action=ARR %then nokeys ; ';
|
|
172
188
|
put ' ;export &tempds / nosastags fmtnumeric; ';
|
|
173
189
|
put ' run; ';
|
|
190
|
+
put ' /* send back to webout */ ';
|
|
191
|
+
put ' data _null_; ';
|
|
192
|
+
put ' infile _sjs2 lrecl=1 recfm=n; ';
|
|
193
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
194
|
+
put ' input sourcechar $char1. @@; ';
|
|
195
|
+
put ' format sourcechar hex2.; ';
|
|
196
|
+
put ' put sourcechar char1. @@; ';
|
|
197
|
+
put ' run; ';
|
|
198
|
+
put ' filename _sjs2 clear; ';
|
|
174
199
|
put ' %end; ';
|
|
175
200
|
put ' %else %if &engine=DATASTEP %then %do; ';
|
|
176
201
|
put ' %datastep: ';
|
|
@@ -253,10 +278,9 @@ data _null_;
|
|
|
253
278
|
put ' %end; ';
|
|
254
279
|
put ' run; ';
|
|
255
280
|
put ' ';
|
|
256
|
-
put '
|
|
257
|
-
put '
|
|
258
|
-
put '
|
|
259
|
-
put ' data _null_; file _sjs lrecl=131068 encoding=''utf-8'' mod ; ';
|
|
281
|
+
put ' filename _sjs3 temp lrecl=131068 ; ';
|
|
282
|
+
put ' data _null_; ';
|
|
283
|
+
put ' file _sjs3 encoding=''utf-8''; ';
|
|
260
284
|
put ' if _n_=1 then put "["; ';
|
|
261
285
|
put ' set &tempds; ';
|
|
262
286
|
put ' if _n_>1 then put "," @; put ';
|
|
@@ -267,31 +291,29 @@ data _null_;
|
|
|
267
291
|
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
|
268
292
|
put ' %end; ';
|
|
269
293
|
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
|
270
|
-
put '
|
|
294
|
+
put ' ';
|
|
295
|
+
put ' /* close out the table */ ';
|
|
271
296
|
put ' data _null_; ';
|
|
272
|
-
put '
|
|
273
|
-
put '
|
|
274
|
-
put ' fileid=fopen("&jref",''A'',1,''B''); ';
|
|
275
|
-
put ' rec=''20''x; ';
|
|
276
|
-
put ' do while(fread(filein)=0); ';
|
|
277
|
-
put ' rc=fget(filein,rec,1); ';
|
|
278
|
-
put ' rc=fput(fileid, rec); ';
|
|
279
|
-
put ' rc=fwrite(fileid); ';
|
|
280
|
-
put ' end; ';
|
|
281
|
-
put ' /* close out the table */ ';
|
|
282
|
-
put ' rc=fput(fileid, "]"); ';
|
|
283
|
-
put ' rc=fwrite(fileid); ';
|
|
284
|
-
put ' rc=fclose(filein); ';
|
|
285
|
-
put ' rc=fclose(fileid); ';
|
|
297
|
+
put ' file _sjs3 mod encoding=''utf-8''; ';
|
|
298
|
+
put ' put '']''; ';
|
|
286
299
|
put ' run; ';
|
|
287
|
-
put '
|
|
300
|
+
put ' data _null_; ';
|
|
301
|
+
put ' infile _sjs3 lrecl=1 recfm=n; ';
|
|
302
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
303
|
+
put ' input sourcechar $char1. @@; ';
|
|
304
|
+
put ' format sourcechar hex2.; ';
|
|
305
|
+
put ' put sourcechar char1. @@; ';
|
|
306
|
+
put ' run; ';
|
|
307
|
+
put ' filename _sjs3 clear; ';
|
|
288
308
|
put ' %end; ';
|
|
289
309
|
put ' ';
|
|
290
310
|
put ' proc sql; ';
|
|
291
311
|
put ' drop table &colinfo, &tempds; ';
|
|
292
312
|
put ' ';
|
|
293
313
|
put ' %if &showmeta=YES %then %do; ';
|
|
294
|
-
put '
|
|
314
|
+
put ' filename _sjs4 temp lrecl=131068 encoding=''utf-8''; ';
|
|
315
|
+
put ' data _null_; ';
|
|
316
|
+
put ' file _sjs4; ';
|
|
295
317
|
put ' put ", ""$%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":{""vars"":{"; ';
|
|
296
318
|
put ' do i=1 to &numcols; ';
|
|
297
319
|
put ' name=quote(trim(symget(cats(''name'',i)))); ';
|
|
@@ -305,6 +327,15 @@ data _null_;
|
|
|
305
327
|
put ' end; ';
|
|
306
328
|
put ' put ''}}''; ';
|
|
307
329
|
put ' run; ';
|
|
330
|
+
put ' /* send back to webout */ ';
|
|
331
|
+
put ' data _null_; ';
|
|
332
|
+
put ' infile _sjs4 lrecl=1 recfm=n; ';
|
|
333
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
334
|
+
put ' input sourcechar $char1. @@; ';
|
|
335
|
+
put ' format sourcechar hex2.; ';
|
|
336
|
+
put ' put sourcechar char1. @@; ';
|
|
337
|
+
put ' run; ';
|
|
338
|
+
put ' filename _sjs4 clear; ';
|
|
308
339
|
put ' %end; ';
|
|
309
340
|
put '%end; ';
|
|
310
341
|
put ' ';
|
|
@@ -406,6 +437,8 @@ data _null_;
|
|
|
406
437
|
put ' ) ';
|
|
407
438
|
put '%end; ';
|
|
408
439
|
put '%else %if &action=CLOSE %then %do; ';
|
|
440
|
+
put ' /* To avoid issues with _webout on EBI we use a temporary file */ ';
|
|
441
|
+
put ' filename _sjsref temp lrecl=131068; ';
|
|
409
442
|
put ' %if %str(&_debug) ge 131 %then %do; ';
|
|
410
443
|
put ' /* if debug mode, send back first 10 records of each work table also */ ';
|
|
411
444
|
put ' options obs=10; ';
|
|
@@ -419,11 +452,11 @@ data _null_;
|
|
|
419
452
|
put ' i+1; ';
|
|
420
453
|
put ' call symputx(cats(''wt'',i),name,''l''); ';
|
|
421
454
|
put ' call symputx(''wtcnt'',i,''l''); ';
|
|
422
|
-
put ' data _null_; file
|
|
455
|
+
put ' data _null_; file _sjsref mod encoding=''utf-8''; ';
|
|
423
456
|
put ' put ",""WORK"":{"; ';
|
|
424
457
|
put ' %do i=1 %to &wtcnt; ';
|
|
425
458
|
put ' %let wt=&&wt&i; ';
|
|
426
|
-
put ' data _null_; file
|
|
459
|
+
put ' data _null_; file _sjsref mod encoding=''utf-8''; ';
|
|
427
460
|
put ' dsid=open("WORK.&wt",''is''); ';
|
|
428
461
|
put ' nlobs=attrn(dsid,''NLOBS''); ';
|
|
429
462
|
put ' nvars=attrn(dsid,''NVARS''); ';
|
|
@@ -432,16 +465,16 @@ data _null_;
|
|
|
432
465
|
put ' put " ""&wt"" : {"; ';
|
|
433
466
|
put ' put ''"nlobs":'' nlobs; ';
|
|
434
467
|
put ' put '',"nvars":'' nvars; ';
|
|
435
|
-
put ' %mp_jsonout(OBJ,&wt,jref
|
|
436
|
-
put ' data _null_; file
|
|
468
|
+
put ' %mp_jsonout(OBJ,&wt,jref=_sjsref,dslabel=first10rows,showmeta=YES) ';
|
|
469
|
+
put ' data _null_; file _sjsref mod encoding=''utf-8''; ';
|
|
437
470
|
put ' put "}"; ';
|
|
438
471
|
put ' %end; ';
|
|
439
|
-
put ' data _null_; file
|
|
472
|
+
put ' data _null_; file _sjsref mod encoding=''utf-8''; ';
|
|
440
473
|
put ' put "}"; ';
|
|
441
474
|
put ' run; ';
|
|
442
475
|
put ' %end; ';
|
|
443
476
|
put ' /* close off json */ ';
|
|
444
|
-
put ' data _null_;file
|
|
477
|
+
put ' data _null_;file _sjsref mod encoding=''utf-8''; ';
|
|
445
478
|
put ' _PROGRAM=quote(trim(resolve(symget(''_PROGRAM'')))); ';
|
|
446
479
|
put ' put ",""SYSUSERID"" : ""&sysuserid"" "; ';
|
|
447
480
|
put ' put ",""MF_GETUSER"" : ""%mf_getuser()"" "; ';
|
|
@@ -473,6 +506,16 @@ data _null_;
|
|
|
473
506
|
put ' put ''>>weboutEND<<''; ';
|
|
474
507
|
put ' %end; ';
|
|
475
508
|
put ' run; ';
|
|
509
|
+
put ' /* now write to _webout 1 char at a time */ ';
|
|
510
|
+
put ' data _null_; ';
|
|
511
|
+
put ' infile _sjsref lrecl=1 recfm=n; ';
|
|
512
|
+
put ' file &fref mod lrecl=1 recfm=n; ';
|
|
513
|
+
put ' input sourcechar $char1. @@; ';
|
|
514
|
+
put ' format sourcechar hex2.; ';
|
|
515
|
+
put ' put sourcechar char1. @@; ';
|
|
516
|
+
put ' run; ';
|
|
517
|
+
put ' filename _sjsref clear; ';
|
|
518
|
+
put ' ';
|
|
476
519
|
put '%end; ';
|
|
477
520
|
put ' ';
|
|
478
521
|
put '%mend mm_webout; ';
|
|
@@ -494,7 +537,7 @@ run;
|
|
|
494
537
|
%if &x>1 %then %let mod=mod;
|
|
495
538
|
|
|
496
539
|
%let fref=%scan(&freflist,&x);
|
|
497
|
-
|
|
540
|
+
%&mD.put &sysmacroname: adding &fref;
|
|
498
541
|
data _null_;
|
|
499
542
|
file "&work/&tmpfile" lrecl=3000 &mod;
|
|
500
543
|
infile &fref;
|
|
@@ -530,12 +573,10 @@ data _null_;
|
|
|
530
573
|
if rc=0 then call symputx('url',url,'l');
|
|
531
574
|
run;
|
|
532
575
|
|
|
533
|
-
%put ;%put ;%put ;%put ;%put ;%put ;
|
|
534
576
|
%put &sysmacroname: STP &name successfully created in &path;
|
|
535
|
-
%put ;%put ;%put ;
|
|
536
577
|
%put Check it out here:;
|
|
537
578
|
%put ;%put ;%put ;
|
|
538
579
|
%put &url?_PROGRAM=&path/&name;
|
|
539
|
-
%put ;%put ;%put
|
|
580
|
+
%put ;%put ;%put ;
|
|
540
581
|
|
|
541
582
|
%mend mm_createwebservice;
|
package/meta/mm_webout.sas
CHANGED
|
@@ -4,23 +4,23 @@
|
|
|
4
4
|
@details This macro should be added to the start of each Stored Process,
|
|
5
5
|
**immediately** followed by a call to:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
%mm_webout(FETCH)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
This will read all the input data and create same-named SAS datasets in the
|
|
10
|
+
WORK library. You can then insert your code, and send data back using the
|
|
11
|
+
following syntax:
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
data some datasets; * make some data ;
|
|
14
|
+
retain some columns;
|
|
15
|
+
run;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
%mm_webout(OPEN)
|
|
18
|
+
%mm_webout(ARR,some) * Array format, fast, suitable for large tables ;
|
|
19
|
+
%mm_webout(OBJ,datasets) * Object format, easier to work with ;
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Finally, wrap everything up send some helpful system variables too
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
%mm_webout(CLOSE)
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
@param [in] action Either FETCH, OPEN, ARR, OBJ or CLOSE
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
object with the same name as the table but prefixed with a dollar sign - ie,
|
|
36
36
|
`,"$tablename":{"formats":{"col1":"$CHAR1"},"types":{"COL1":"C"}}`
|
|
37
37
|
|
|
38
|
+
|
|
39
|
+
<h4> SAS Macros </h4>
|
|
40
|
+
@li mp_jsonout.sas
|
|
41
|
+
|
|
38
42
|
@version 9.3
|
|
39
43
|
@author Allan Bowe
|
|
40
44
|
|
|
@@ -111,6 +115,8 @@
|
|
|
111
115
|
)
|
|
112
116
|
%end;
|
|
113
117
|
%else %if &action=CLOSE %then %do;
|
|
118
|
+
/* To avoid issues with _webout on EBI we use a temporary file */
|
|
119
|
+
filename _sjsref temp lrecl=131068;
|
|
114
120
|
%if %str(&_debug) ge 131 %then %do;
|
|
115
121
|
/* if debug mode, send back first 10 records of each work table also */
|
|
116
122
|
options obs=10;
|
|
@@ -124,11 +130,11 @@
|
|
|
124
130
|
i+1;
|
|
125
131
|
call symputx(cats('wt',i),name,'l');
|
|
126
132
|
call symputx('wtcnt',i,'l');
|
|
127
|
-
data _null_; file
|
|
133
|
+
data _null_; file _sjsref mod encoding='utf-8';
|
|
128
134
|
put ",""WORK"":{";
|
|
129
135
|
%do i=1 %to &wtcnt;
|
|
130
136
|
%let wt=&&wt&i;
|
|
131
|
-
data _null_; file
|
|
137
|
+
data _null_; file _sjsref mod encoding='utf-8';
|
|
132
138
|
dsid=open("WORK.&wt",'is');
|
|
133
139
|
nlobs=attrn(dsid,'NLOBS');
|
|
134
140
|
nvars=attrn(dsid,'NVARS');
|
|
@@ -137,16 +143,16 @@
|
|
|
137
143
|
put " ""&wt"" : {";
|
|
138
144
|
put '"nlobs":' nlobs;
|
|
139
145
|
put ',"nvars":' nvars;
|
|
140
|
-
%mp_jsonout(OBJ,&wt,jref
|
|
141
|
-
data _null_; file
|
|
146
|
+
%mp_jsonout(OBJ,&wt,jref=_sjsref,dslabel=first10rows,showmeta=YES)
|
|
147
|
+
data _null_; file _sjsref mod encoding='utf-8';
|
|
142
148
|
put "}";
|
|
143
149
|
%end;
|
|
144
|
-
data _null_; file
|
|
150
|
+
data _null_; file _sjsref mod encoding='utf-8';
|
|
145
151
|
put "}";
|
|
146
152
|
run;
|
|
147
153
|
%end;
|
|
148
154
|
/* close off json */
|
|
149
|
-
data _null_;file
|
|
155
|
+
data _null_;file _sjsref mod encoding='utf-8';
|
|
150
156
|
_PROGRAM=quote(trim(resolve(symget('_PROGRAM'))));
|
|
151
157
|
put ",""SYSUSERID"" : ""&sysuserid"" ";
|
|
152
158
|
put ",""MF_GETUSER"" : ""%mf_getuser()"" ";
|
|
@@ -178,6 +184,16 @@
|
|
|
178
184
|
put '>>weboutEND<<';
|
|
179
185
|
%end;
|
|
180
186
|
run;
|
|
187
|
+
/* now write to _webout 1 char at a time */
|
|
188
|
+
data _null_;
|
|
189
|
+
infile _sjsref lrecl=1 recfm=n;
|
|
190
|
+
file &fref mod lrecl=1 recfm=n;
|
|
191
|
+
input sourcechar $char1. @@;
|
|
192
|
+
format sourcechar hex2.;
|
|
193
|
+
put sourcechar char1. @@;
|
|
194
|
+
run;
|
|
195
|
+
filename _sjsref clear;
|
|
196
|
+
|
|
181
197
|
%end;
|
|
182
198
|
|
|
183
199
|
%mend mm_webout;
|
package/package.json
CHANGED
|
@@ -110,9 +110,23 @@ data _null_;
|
|
|
110
110
|
put ' run; ';
|
|
111
111
|
put '%end; ';
|
|
112
112
|
put '%else %if (&action=ARR or &action=OBJ) %then %do; ';
|
|
113
|
+
put ' /* force variable names to always be uppercase in the JSON */ ';
|
|
113
114
|
put ' options validvarname=upcase; ';
|
|
114
|
-
put '
|
|
115
|
+
put ' /* To avoid issues with _webout on EBI - such as encoding diffs and truncation ';
|
|
116
|
+
put ' (https://support.sas.com/kb/49/325.html) we use temporary files */ ';
|
|
117
|
+
put ' filename _sjs1 temp lrecl=200 ; ';
|
|
118
|
+
put ' data _null_; file _sjs1 encoding=''utf-8''; ';
|
|
115
119
|
put ' put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":"; ';
|
|
120
|
+
put ' run; ';
|
|
121
|
+
put ' /* now write to _webout 1 char at a time */ ';
|
|
122
|
+
put ' data _null_; ';
|
|
123
|
+
put ' infile _sjs1 lrecl=1 recfm=n; ';
|
|
124
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
125
|
+
put ' input sourcechar $char1. @@; ';
|
|
126
|
+
put ' format sourcechar hex2.; ';
|
|
127
|
+
put ' put sourcechar char1. @@; ';
|
|
128
|
+
put ' run; ';
|
|
129
|
+
put ' filename _sjs1 clear; ';
|
|
116
130
|
put ' ';
|
|
117
131
|
put ' /* grab col defs */ ';
|
|
118
132
|
put ' proc contents noprint data=&ds ';
|
|
@@ -169,10 +183,20 @@ data _null_;
|
|
|
169
183
|
put ' data &tempds;set &ds; ';
|
|
170
184
|
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
|
171
185
|
put ' /* PRETTY is necessary to avoid line truncation in large files */ ';
|
|
172
|
-
put '
|
|
186
|
+
put ' filename _sjs2 temp lrecl=131068 encoding=''utf-8''; ';
|
|
187
|
+
put ' proc json out=_sjs2 pretty ';
|
|
173
188
|
put ' %if &action=ARR %then nokeys ; ';
|
|
174
189
|
put ' ;export &tempds / nosastags fmtnumeric; ';
|
|
175
190
|
put ' run; ';
|
|
191
|
+
put ' /* send back to webout */ ';
|
|
192
|
+
put ' data _null_; ';
|
|
193
|
+
put ' infile _sjs2 lrecl=1 recfm=n; ';
|
|
194
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
195
|
+
put ' input sourcechar $char1. @@; ';
|
|
196
|
+
put ' format sourcechar hex2.; ';
|
|
197
|
+
put ' put sourcechar char1. @@; ';
|
|
198
|
+
put ' run; ';
|
|
199
|
+
put ' filename _sjs2 clear; ';
|
|
176
200
|
put ' %end; ';
|
|
177
201
|
put ' %else %if &engine=DATASTEP %then %do; ';
|
|
178
202
|
put ' %datastep: ';
|
|
@@ -255,10 +279,9 @@ data _null_;
|
|
|
255
279
|
put ' %end; ';
|
|
256
280
|
put ' run; ';
|
|
257
281
|
put ' ';
|
|
258
|
-
put '
|
|
259
|
-
put '
|
|
260
|
-
put '
|
|
261
|
-
put ' data _null_; file _sjs lrecl=131068 encoding=''utf-8'' mod ; ';
|
|
282
|
+
put ' filename _sjs3 temp lrecl=131068 ; ';
|
|
283
|
+
put ' data _null_; ';
|
|
284
|
+
put ' file _sjs3 encoding=''utf-8''; ';
|
|
262
285
|
put ' if _n_=1 then put "["; ';
|
|
263
286
|
put ' set &tempds; ';
|
|
264
287
|
put ' if _n_>1 then put "," @; put ';
|
|
@@ -269,31 +292,29 @@ data _null_;
|
|
|
269
292
|
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
|
270
293
|
put ' %end; ';
|
|
271
294
|
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
|
272
|
-
put '
|
|
295
|
+
put ' ';
|
|
296
|
+
put ' /* close out the table */ ';
|
|
273
297
|
put ' data _null_; ';
|
|
274
|
-
put '
|
|
275
|
-
put '
|
|
276
|
-
put '
|
|
277
|
-
put '
|
|
278
|
-
put '
|
|
279
|
-
put '
|
|
280
|
-
put '
|
|
281
|
-
put '
|
|
282
|
-
put '
|
|
283
|
-
put ' /* close out the table */ ';
|
|
284
|
-
put ' rc=fput(fileid, "]"); ';
|
|
285
|
-
put ' rc=fwrite(fileid); ';
|
|
286
|
-
put ' rc=fclose(filein); ';
|
|
287
|
-
put ' rc=fclose(fileid); ';
|
|
298
|
+
put ' file _sjs3 mod encoding=''utf-8''; ';
|
|
299
|
+
put ' put '']''; ';
|
|
300
|
+
put ' run; ';
|
|
301
|
+
put ' data _null_; ';
|
|
302
|
+
put ' infile _sjs3 lrecl=1 recfm=n; ';
|
|
303
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
304
|
+
put ' input sourcechar $char1. @@; ';
|
|
305
|
+
put ' format sourcechar hex2.; ';
|
|
306
|
+
put ' put sourcechar char1. @@; ';
|
|
288
307
|
put ' run; ';
|
|
289
|
-
put ' filename
|
|
308
|
+
put ' filename _sjs3 clear; ';
|
|
290
309
|
put ' %end; ';
|
|
291
310
|
put ' ';
|
|
292
311
|
put ' proc sql; ';
|
|
293
312
|
put ' drop table &colinfo, &tempds; ';
|
|
294
313
|
put ' ';
|
|
295
314
|
put ' %if &showmeta=YES %then %do; ';
|
|
296
|
-
put '
|
|
315
|
+
put ' filename _sjs4 temp lrecl=131068 encoding=''utf-8''; ';
|
|
316
|
+
put ' data _null_; ';
|
|
317
|
+
put ' file _sjs4; ';
|
|
297
318
|
put ' put ", ""$%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":{""vars"":{"; ';
|
|
298
319
|
put ' do i=1 to &numcols; ';
|
|
299
320
|
put ' name=quote(trim(symget(cats(''name'',i)))); ';
|
|
@@ -307,6 +328,15 @@ data _null_;
|
|
|
307
328
|
put ' end; ';
|
|
308
329
|
put ' put ''}}''; ';
|
|
309
330
|
put ' run; ';
|
|
331
|
+
put ' /* send back to webout */ ';
|
|
332
|
+
put ' data _null_; ';
|
|
333
|
+
put ' infile _sjs4 lrecl=1 recfm=n; ';
|
|
334
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
335
|
+
put ' input sourcechar $char1. @@; ';
|
|
336
|
+
put ' format sourcechar hex2.; ';
|
|
337
|
+
put ' put sourcechar char1. @@; ';
|
|
338
|
+
put ' run; ';
|
|
339
|
+
put ' filename _sjs4 clear; ';
|
|
310
340
|
put ' %end; ';
|
|
311
341
|
put '%end; ';
|
|
312
342
|
put ' ';
|
|
@@ -252,9 +252,23 @@ data _null_;
|
|
|
252
252
|
put ' run; ';
|
|
253
253
|
put '%end; ';
|
|
254
254
|
put '%else %if (&action=ARR or &action=OBJ) %then %do; ';
|
|
255
|
+
put ' /* force variable names to always be uppercase in the JSON */ ';
|
|
255
256
|
put ' options validvarname=upcase; ';
|
|
256
|
-
put '
|
|
257
|
+
put ' /* To avoid issues with _webout on EBI - such as encoding diffs and truncation ';
|
|
258
|
+
put ' (https://support.sas.com/kb/49/325.html) we use temporary files */ ';
|
|
259
|
+
put ' filename _sjs1 temp lrecl=200 ; ';
|
|
260
|
+
put ' data _null_; file _sjs1 encoding=''utf-8''; ';
|
|
257
261
|
put ' put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":"; ';
|
|
262
|
+
put ' run; ';
|
|
263
|
+
put ' /* now write to _webout 1 char at a time */ ';
|
|
264
|
+
put ' data _null_; ';
|
|
265
|
+
put ' infile _sjs1 lrecl=1 recfm=n; ';
|
|
266
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
267
|
+
put ' input sourcechar $char1. @@; ';
|
|
268
|
+
put ' format sourcechar hex2.; ';
|
|
269
|
+
put ' put sourcechar char1. @@; ';
|
|
270
|
+
put ' run; ';
|
|
271
|
+
put ' filename _sjs1 clear; ';
|
|
258
272
|
put ' ';
|
|
259
273
|
put ' /* grab col defs */ ';
|
|
260
274
|
put ' proc contents noprint data=&ds ';
|
|
@@ -311,10 +325,20 @@ data _null_;
|
|
|
311
325
|
put ' data &tempds;set &ds; ';
|
|
312
326
|
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
|
313
327
|
put ' /* PRETTY is necessary to avoid line truncation in large files */ ';
|
|
314
|
-
put '
|
|
328
|
+
put ' filename _sjs2 temp lrecl=131068 encoding=''utf-8''; ';
|
|
329
|
+
put ' proc json out=_sjs2 pretty ';
|
|
315
330
|
put ' %if &action=ARR %then nokeys ; ';
|
|
316
331
|
put ' ;export &tempds / nosastags fmtnumeric; ';
|
|
317
332
|
put ' run; ';
|
|
333
|
+
put ' /* send back to webout */ ';
|
|
334
|
+
put ' data _null_; ';
|
|
335
|
+
put ' infile _sjs2 lrecl=1 recfm=n; ';
|
|
336
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
337
|
+
put ' input sourcechar $char1. @@; ';
|
|
338
|
+
put ' format sourcechar hex2.; ';
|
|
339
|
+
put ' put sourcechar char1. @@; ';
|
|
340
|
+
put ' run; ';
|
|
341
|
+
put ' filename _sjs2 clear; ';
|
|
318
342
|
put ' %end; ';
|
|
319
343
|
put ' %else %if &engine=DATASTEP %then %do; ';
|
|
320
344
|
put ' %datastep: ';
|
|
@@ -397,10 +421,9 @@ data _null_;
|
|
|
397
421
|
put ' %end; ';
|
|
398
422
|
put ' run; ';
|
|
399
423
|
put ' ';
|
|
400
|
-
put '
|
|
401
|
-
put '
|
|
402
|
-
put '
|
|
403
|
-
put ' data _null_; file _sjs lrecl=131068 encoding=''utf-8'' mod ; ';
|
|
424
|
+
put ' filename _sjs3 temp lrecl=131068 ; ';
|
|
425
|
+
put ' data _null_; ';
|
|
426
|
+
put ' file _sjs3 encoding=''utf-8''; ';
|
|
404
427
|
put ' if _n_=1 then put "["; ';
|
|
405
428
|
put ' set &tempds; ';
|
|
406
429
|
put ' if _n_>1 then put "," @; put ';
|
|
@@ -411,31 +434,29 @@ data _null_;
|
|
|
411
434
|
put ' "&&name&i"n /* name literal for reserved variable names */ ';
|
|
412
435
|
put ' %end; ';
|
|
413
436
|
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
|
414
|
-
put '
|
|
437
|
+
put ' ';
|
|
438
|
+
put ' /* close out the table */ ';
|
|
415
439
|
put ' data _null_; ';
|
|
416
|
-
put '
|
|
417
|
-
put '
|
|
418
|
-
put '
|
|
419
|
-
put '
|
|
420
|
-
put '
|
|
421
|
-
put '
|
|
422
|
-
put '
|
|
423
|
-
put '
|
|
424
|
-
put '
|
|
425
|
-
put ' /* close out the table */ ';
|
|
426
|
-
put ' rc=fput(fileid, "]"); ';
|
|
427
|
-
put ' rc=fwrite(fileid); ';
|
|
428
|
-
put ' rc=fclose(filein); ';
|
|
429
|
-
put ' rc=fclose(fileid); ';
|
|
440
|
+
put ' file _sjs3 mod encoding=''utf-8''; ';
|
|
441
|
+
put ' put '']''; ';
|
|
442
|
+
put ' run; ';
|
|
443
|
+
put ' data _null_; ';
|
|
444
|
+
put ' infile _sjs3 lrecl=1 recfm=n; ';
|
|
445
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
446
|
+
put ' input sourcechar $char1. @@; ';
|
|
447
|
+
put ' format sourcechar hex2.; ';
|
|
448
|
+
put ' put sourcechar char1. @@; ';
|
|
430
449
|
put ' run; ';
|
|
431
|
-
put ' filename
|
|
450
|
+
put ' filename _sjs3 clear; ';
|
|
432
451
|
put ' %end; ';
|
|
433
452
|
put ' ';
|
|
434
453
|
put ' proc sql; ';
|
|
435
454
|
put ' drop table &colinfo, &tempds; ';
|
|
436
455
|
put ' ';
|
|
437
456
|
put ' %if &showmeta=YES %then %do; ';
|
|
438
|
-
put '
|
|
457
|
+
put ' filename _sjs4 temp lrecl=131068 encoding=''utf-8''; ';
|
|
458
|
+
put ' data _null_; ';
|
|
459
|
+
put ' file _sjs4; ';
|
|
439
460
|
put ' put ", ""$%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":{""vars"":{"; ';
|
|
440
461
|
put ' do i=1 to &numcols; ';
|
|
441
462
|
put ' name=quote(trim(symget(cats(''name'',i)))); ';
|
|
@@ -449,6 +470,15 @@ data _null_;
|
|
|
449
470
|
put ' end; ';
|
|
450
471
|
put ' put ''}}''; ';
|
|
451
472
|
put ' run; ';
|
|
473
|
+
put ' /* send back to webout */ ';
|
|
474
|
+
put ' data _null_; ';
|
|
475
|
+
put ' infile _sjs4 lrecl=1 recfm=n; ';
|
|
476
|
+
put ' file &jref mod lrecl=1 recfm=n; ';
|
|
477
|
+
put ' input sourcechar $char1. @@; ';
|
|
478
|
+
put ' format sourcechar hex2.; ';
|
|
479
|
+
put ' put sourcechar char1. @@; ';
|
|
480
|
+
put ' run; ';
|
|
481
|
+
put ' filename _sjs4 clear; ';
|
|
452
482
|
put ' %end; ';
|
|
453
483
|
put '%end; ';
|
|
454
484
|
put ' ';
|