@sasjs/core 3.7.5 → 3.9.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.
- package/README.md +7 -0
- package/base/mp_jsonout.sas +138 -102
- package/base/mp_lockanytable.sas +1 -1
- package/meta/mm_createstp.sas +11 -8
- package/meta/mm_createwebservice.sas +152 -111
- package/meta/mm_webout.sas +21 -13
- package/package.json +2 -2
- package/server/ms_webout.sas +16 -12
- package/viya/mv_createwebservice.sas +141 -104
- package/viya/mv_webout.sas +23 -15
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
that location
|
|
55
55
|
@param [in] adapter= the macro uses the sasjs adapter by default. To use
|
|
56
56
|
another adapter, add a (different) fileref here.
|
|
57
|
-
@param [in] contextname= Choose a specific context on which to run the Job.
|
|
58
|
-
blank to use the default context. From Viya 3.5 it is possible to
|
|
59
|
-
a shared context - see
|
|
57
|
+
@param [in] contextname= Choose a specific context on which to run the Job.
|
|
58
|
+
Leave blank to use the default context. From Viya 3.5 it is possible to
|
|
59
|
+
configure a shared context - see
|
|
60
60
|
https://go.documentation.sas.com/?docsetId=calcontexts&docsetTarget=n1hjn8eobk5pyhn1wg3ja0drdl6h.htm&docsetVersion=3.5&locale=en
|
|
61
61
|
@param [in] mdebug=(0) set to 1 to enable DEBUG messages
|
|
62
62
|
|
|
@@ -237,9 +237,15 @@ data _null_;
|
|
|
237
237
|
put "/* Created on %sysfunc(datetime(),datetime19.) by &sysuserid */";
|
|
238
238
|
/* WEBOUT BEGIN */
|
|
239
239
|
put ' ';
|
|
240
|
-
put '%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y
|
|
240
|
+
put '%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y ';
|
|
241
|
+
put ' ,engine=DATASTEP ';
|
|
242
|
+
put ' ,dbg=0 /* DEPRECATED */ ';
|
|
243
|
+
put ' ,missing=NULL ';
|
|
244
|
+
put ' ,showmeta=NO ';
|
|
241
245
|
put ')/*/STORE SOURCE*/; ';
|
|
242
|
-
put '%
|
|
246
|
+
put '%local tempds colinfo fmtds i numcols; ';
|
|
247
|
+
put '%let numcols=0; ';
|
|
248
|
+
put ' ';
|
|
243
249
|
put '%if &action=OPEN %then %do; ';
|
|
244
250
|
put ' options nobomfile; ';
|
|
245
251
|
put ' data _null_;file &jref encoding=''utf-8'' ; ';
|
|
@@ -248,118 +254,124 @@ data _null_;
|
|
|
248
254
|
put '%end; ';
|
|
249
255
|
put '%else %if (&action=ARR or &action=OBJ) %then %do; ';
|
|
250
256
|
put ' options validvarname=upcase; ';
|
|
251
|
-
put ' data _null_;file &jref
|
|
257
|
+
put ' data _null_; file &jref encoding=''utf-8'' mod; ';
|
|
252
258
|
put ' put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":"; ';
|
|
253
259
|
put ' ';
|
|
260
|
+
put ' /* grab col defs */ ';
|
|
261
|
+
put ' proc contents noprint data=&ds ';
|
|
262
|
+
put ' out=_data_(keep=name type length format formatl formatd varnum label); ';
|
|
263
|
+
put ' run; ';
|
|
264
|
+
put ' %let colinfo=%scan(&syslast,2,.); ';
|
|
265
|
+
put ' proc sort data=&colinfo; ';
|
|
266
|
+
put ' by varnum; ';
|
|
267
|
+
put ' run; ';
|
|
268
|
+
put ' /* move meta to mac vars */ ';
|
|
269
|
+
put ' data _null_; ';
|
|
270
|
+
put ' if _n_=1 then call symputx(''numcols'',nobs,''l''); ';
|
|
271
|
+
put ' set &colinfo end=last nobs=nobs; ';
|
|
272
|
+
put ' name=upcase(name); ';
|
|
273
|
+
put ' /* fix formats */ ';
|
|
274
|
+
put ' if type=2 or type=6 then do; ';
|
|
275
|
+
put ' typelong=''char''; ';
|
|
276
|
+
put ' length fmt $49.; ';
|
|
277
|
+
put ' if format='''' then fmt=cats(''$'',length,''.''); ';
|
|
278
|
+
put ' else if formatl=0 then fmt=cats(format,''.''); ';
|
|
279
|
+
put ' else fmt=cats(format,formatl,''.''); ';
|
|
280
|
+
put ' newlen=max(formatl,length); ';
|
|
281
|
+
put ' end; ';
|
|
282
|
+
put ' else do; ';
|
|
283
|
+
put ' typelong=''num''; ';
|
|
284
|
+
put ' if format='''' then fmt=''best.''; ';
|
|
285
|
+
put ' else if formatl=0 then fmt=cats(format,''.''); ';
|
|
286
|
+
put ' else if formatd=0 then fmt=cats(format,formatl,''.''); ';
|
|
287
|
+
put ' else fmt=cats(format,formatl,''.'',formatd); ';
|
|
288
|
+
put ' /* needs to be wide, for datetimes etc */ ';
|
|
289
|
+
put ' newlen=max(length,formatl,24); ';
|
|
290
|
+
put ' end; ';
|
|
291
|
+
put ' /* 32 char unique name */ ';
|
|
292
|
+
put ' newname=''sasjs''!!substr(cats(put(md5(name),$hex32.)),1,27); ';
|
|
293
|
+
put ' ';
|
|
294
|
+
put ' call symputx(cats(''name'',_n_),name,''l''); ';
|
|
295
|
+
put ' call symputx(cats(''newname'',_n_),newname,''l''); ';
|
|
296
|
+
put ' call symputx(cats(''len'',_n_),newlen,''l''); ';
|
|
297
|
+
put ' call symputx(cats(''length'',_n_),length,''l''); ';
|
|
298
|
+
put ' call symputx(cats(''fmt'',_n_),fmt,''l''); ';
|
|
299
|
+
put ' call symputx(cats(''type'',_n_),type,''l''); ';
|
|
300
|
+
put ' call symputx(cats(''typelong'',_n_),typelong,''l''); ';
|
|
301
|
+
put ' call symputx(cats(''label'',_n_),coalescec(label,name),''l''); ';
|
|
302
|
+
put ' run; ';
|
|
303
|
+
put ' ';
|
|
304
|
+
put ' %let tempds=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
|
|
305
|
+
put ' ';
|
|
254
306
|
put ' %if &engine=PROCJSON %then %do; ';
|
|
255
|
-
put '
|
|
256
|
-
put '
|
|
307
|
+
put ' %if &missing=STRING %then %do; ';
|
|
308
|
+
put ' %put &sysmacroname: Special Missings not supported in proc json.; ';
|
|
309
|
+
put ' %put &sysmacroname: Switching to DATASTEP engine; ';
|
|
310
|
+
put ' %goto datastep; ';
|
|
311
|
+
put ' %end; ';
|
|
257
312
|
put ' data &tempds /view=&tempds;set &ds; ';
|
|
258
313
|
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
|
314
|
+
put ' /* PRETTY is necessary to avoid line truncation in large files */ ';
|
|
259
315
|
put ' proc json out=&jref pretty ';
|
|
260
316
|
put ' %if &action=ARR %then nokeys ; ';
|
|
261
317
|
put ' ;export &tempds / nosastags fmtnumeric; ';
|
|
262
318
|
put ' run; ';
|
|
263
|
-
put ' proc sql;drop view &tempds; ';
|
|
264
319
|
put ' %end; ';
|
|
265
320
|
put ' %else %if &engine=DATASTEP %then %do; ';
|
|
266
|
-
put ' %
|
|
267
|
-
put ' %
|
|
268
|
-
put ' %
|
|
321
|
+
put ' %datastep: ';
|
|
322
|
+
put ' %if %sysfunc(exist(&ds)) ne 1 & %sysfunc(exist(&ds,VIEW)) ne 1 ';
|
|
323
|
+
put ' %then %do; ';
|
|
269
324
|
put ' %put &sysmacroname: &ds NOT FOUND!!!; ';
|
|
270
325
|
put ' %return; ';
|
|
271
326
|
put ' %end; ';
|
|
272
|
-
put ' %if &fmt=Y %then %do; ';
|
|
273
|
-
put ' %put converting every variable to a formatted variable; ';
|
|
274
|
-
put ' /* see mp_ds2fmtds.sas for source */ ';
|
|
275
|
-
put ' proc contents noprint data=&ds ';
|
|
276
|
-
put ' out=_data_(keep=name type length format formatl formatd varnum); ';
|
|
277
|
-
put ' run; ';
|
|
278
|
-
put ' proc sort; ';
|
|
279
|
-
put ' by varnum; ';
|
|
280
|
-
put ' run; ';
|
|
281
|
-
put ' %local fmtds; ';
|
|
282
|
-
put ' %let fmtds=%scan(&syslast,2,.); ';
|
|
283
|
-
put ' /* prepare formats and varnames */ ';
|
|
284
|
-
put ' data _null_; ';
|
|
285
|
-
put ' if _n_=1 then call symputx(''nobs'',nobs,''l''); ';
|
|
286
|
-
put ' set &fmtds end=last nobs=nobs; ';
|
|
287
|
-
put ' name=upcase(name); ';
|
|
288
|
-
put ' /* fix formats */ ';
|
|
289
|
-
put ' if type=2 or type=6 then do; ';
|
|
290
|
-
put ' length fmt $49.; ';
|
|
291
|
-
put ' if format='''' then fmt=cats(''$'',length,''.''); ';
|
|
292
|
-
put ' else if formatl=0 then fmt=cats(format,''.''); ';
|
|
293
|
-
put ' else fmt=cats(format,formatl,''.''); ';
|
|
294
|
-
put ' newlen=max(formatl,length); ';
|
|
295
|
-
put ' end; ';
|
|
296
|
-
put ' else do; ';
|
|
297
|
-
put ' if format='''' then fmt=''best.''; ';
|
|
298
|
-
put ' else if formatl=0 then fmt=cats(format,''.''); ';
|
|
299
|
-
put ' else if formatd=0 then fmt=cats(format,formatl,''.''); ';
|
|
300
|
-
put ' else fmt=cats(format,formatl,''.'',formatd); ';
|
|
301
|
-
put ' /* needs to be wide, for datetimes etc */ ';
|
|
302
|
-
put ' newlen=max(length,formatl,24); ';
|
|
303
|
-
put ' end; ';
|
|
304
|
-
put ' /* 32 char unique name */ ';
|
|
305
|
-
put ' newname=''sasjs''!!substr(cats(put(md5(name),$hex32.)),1,27); ';
|
|
306
327
|
put ' ';
|
|
307
|
-
put '
|
|
308
|
-
put '
|
|
309
|
-
put ' call symputx(cats(''len'',_n_),newlen,''l''); ';
|
|
310
|
-
put ' call symputx(cats(''fmt'',_n_),fmt,''l''); ';
|
|
311
|
-
put ' call symputx(cats(''type'',_n_),type,''l''); ';
|
|
312
|
-
put ' run; ';
|
|
313
|
-
put ' data &fmtds; ';
|
|
328
|
+
put ' %if &fmt=Y %then %do; ';
|
|
329
|
+
put ' data _data_; ';
|
|
314
330
|
put ' /* rename on entry */ ';
|
|
315
331
|
put ' set &ds(rename=( ';
|
|
316
|
-
put ' %
|
|
317
|
-
put ' %do i=1 %to &nobs; ';
|
|
332
|
+
put ' %do i=1 %to &numcols; ';
|
|
318
333
|
put ' &&name&i=&&newname&i ';
|
|
319
334
|
put ' %end; ';
|
|
320
335
|
put ' )); ';
|
|
321
|
-
put ' %do i=1 %to &
|
|
336
|
+
put ' %do i=1 %to &numcols; ';
|
|
322
337
|
put ' length &&name&i $&&len&i; ';
|
|
323
338
|
put ' &&name&i=left(put(&&newname&i,&&fmt&i)); ';
|
|
324
339
|
put ' drop &&newname&i; ';
|
|
325
340
|
put ' %end; ';
|
|
326
341
|
put ' if _error_ then call symputx(''syscc'',1012); ';
|
|
327
342
|
put ' run; ';
|
|
328
|
-
put ' %let
|
|
329
|
-
put ' %end;
|
|
330
|
-
put ' data _null_;file &jref mod encoding=''utf-8'' ; ';
|
|
331
|
-
put ' put "["; call symputx(''cols'',0,''l''); ';
|
|
332
|
-
put ' proc sort ';
|
|
333
|
-
put ' data=sashelp.vcolumn(where=(libname=''WORK'' & memname="%upcase(&ds)")) ';
|
|
334
|
-
put ' out=_data_; ';
|
|
335
|
-
put ' by varnum; ';
|
|
336
|
-
put ' ';
|
|
337
|
-
put ' data _null_; ';
|
|
338
|
-
put ' set _last_ end=last; ';
|
|
339
|
-
put ' call symputx(cats(''name'',_n_),name,''l''); ';
|
|
340
|
-
put ' call symputx(cats(''type'',_n_),type,''l''); ';
|
|
341
|
-
put ' call symputx(cats(''len'',_n_),length,''l''); ';
|
|
342
|
-
put ' if last then call symputx(''cols'',_n_,''l''); ';
|
|
343
|
-
put ' run; ';
|
|
343
|
+
put ' %let fmtds=&syslast; ';
|
|
344
|
+
put ' %end; ';
|
|
344
345
|
put ' ';
|
|
345
346
|
put ' proc format; /* credit yabwon for special null removal */ ';
|
|
346
|
-
put '
|
|
347
|
+
put ' value bart (default=40) ';
|
|
348
|
+
put ' %if &missing=NULL %then %do; ';
|
|
349
|
+
put ' ._ - .z = null ';
|
|
350
|
+
put ' %end; ';
|
|
351
|
+
put ' %else %do; ';
|
|
352
|
+
put ' ._ = [quote()] ';
|
|
353
|
+
put ' . = null ';
|
|
354
|
+
put ' .a - .z = [quote()] ';
|
|
355
|
+
put ' %end; ';
|
|
347
356
|
put ' other = [best.]; ';
|
|
348
357
|
put ' ';
|
|
349
|
-
put ' data;run; %let tempds=&syslast; /* temp table for spesh char management */ ';
|
|
350
|
-
put ' proc sql; drop table &tempds; ';
|
|
351
358
|
put ' data &tempds/view=&tempds; ';
|
|
352
359
|
put ' attrib _all_ label=''''; ';
|
|
353
|
-
put ' %do i=1 %to &
|
|
354
|
-
put ' %if &&
|
|
360
|
+
put ' %do i=1 %to &numcols; ';
|
|
361
|
+
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
|
355
362
|
put ' length &&name&i $32767; ';
|
|
356
363
|
put ' format &&name&i $32767.; ';
|
|
357
364
|
put ' %end; ';
|
|
358
365
|
put ' %end; ';
|
|
359
|
-
put '
|
|
366
|
+
put ' %if &fmt=Y %then %do; ';
|
|
367
|
+
put ' set &fmtds; ';
|
|
368
|
+
put ' %end; ';
|
|
369
|
+
put ' %else %do; ';
|
|
370
|
+
put ' set &ds; ';
|
|
371
|
+
put ' %end; ';
|
|
360
372
|
put ' format _numeric_ bart.; ';
|
|
361
|
-
put ' %do i=1 %to &
|
|
362
|
-
put ' %if &&
|
|
373
|
+
put ' %do i=1 %to &numcols; ';
|
|
374
|
+
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
|
363
375
|
put ' &&name&i=''"''!!trim(prxchange(''s/"/\"/'',-1, ';
|
|
364
376
|
put ' prxchange(''s/''!!''0A''x!!''/\n/'',-1, ';
|
|
365
377
|
put ' prxchange(''s/''!!''0D''x!!''/\r/'',-1, ';
|
|
@@ -369,49 +381,72 @@ data _null_;
|
|
|
369
381
|
put ' %end; ';
|
|
370
382
|
put ' %end; ';
|
|
371
383
|
put ' run; ';
|
|
384
|
+
put ' ';
|
|
372
385
|
put ' /* write to temp loc to avoid _webout truncation ';
|
|
373
386
|
put ' - https://support.sas.com/kb/49/325.html */ ';
|
|
374
387
|
put ' filename _sjs temp lrecl=131068 encoding=''utf-8''; ';
|
|
375
388
|
put ' data _null_; file _sjs lrecl=131068 encoding=''utf-8'' mod ; ';
|
|
389
|
+
put ' if _n_=1 then put "["; ';
|
|
376
390
|
put ' set &tempds; ';
|
|
377
391
|
put ' if _n_>1 then put "," @; put ';
|
|
378
392
|
put ' %if &action=ARR %then "[" ; %else "{" ; ';
|
|
379
|
-
put ' %do i=1 %to &
|
|
393
|
+
put ' %do i=1 %to &numcols; ';
|
|
380
394
|
put ' %if &i>1 %then "," ; ';
|
|
381
395
|
put ' %if &action=OBJ %then """&&name&i"":" ; ';
|
|
382
396
|
put ' &&name&i ';
|
|
383
397
|
put ' %end; ';
|
|
384
398
|
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
|
385
|
-
put ' proc sql; ';
|
|
386
|
-
put ' drop view &tempds; ';
|
|
387
399
|
put ' /* now write the long strings to _webout 1 byte at a time */ ';
|
|
388
400
|
put ' data _null_; ';
|
|
389
401
|
put ' length filein 8 fileid 8; ';
|
|
390
|
-
put ' filein
|
|
391
|
-
put ' fileid
|
|
392
|
-
put ' rec
|
|
402
|
+
put ' filein=fopen("_sjs",''I'',1,''B''); ';
|
|
403
|
+
put ' fileid=fopen("&jref",''A'',1,''B''); ';
|
|
404
|
+
put ' rec=''20''x; ';
|
|
393
405
|
put ' do while(fread(filein)=0); ';
|
|
394
|
-
put ' rc
|
|
395
|
-
put ' rc
|
|
396
|
-
put ' rc
|
|
406
|
+
put ' rc=fget(filein,rec,1); ';
|
|
407
|
+
put ' rc=fput(fileid, rec); ';
|
|
408
|
+
put ' rc=fwrite(fileid); ';
|
|
397
409
|
put ' end; ';
|
|
398
|
-
put '
|
|
399
|
-
put ' rc
|
|
410
|
+
put ' /* close out the table */ ';
|
|
411
|
+
put ' rc=fput(fileid, "]"); ';
|
|
412
|
+
put ' rc=fwrite(fileid); ';
|
|
413
|
+
put ' rc=fclose(filein); ';
|
|
414
|
+
put ' rc=fclose(fileid); ';
|
|
400
415
|
put ' run; ';
|
|
401
416
|
put ' filename _sjs clear; ';
|
|
402
|
-
put '
|
|
403
|
-
put '
|
|
417
|
+
put ' %end; ';
|
|
418
|
+
put ' ';
|
|
419
|
+
put ' proc sql; ';
|
|
420
|
+
put ' drop view &tempds; ';
|
|
421
|
+
put ' drop table &colinfo; ';
|
|
422
|
+
put ' ';
|
|
423
|
+
put ' %if &showmeta=YES %then %do; ';
|
|
424
|
+
put ' data _null_; file &jref encoding=''utf-8'' mod; ';
|
|
425
|
+
put ' put ", ""$%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":{""vars"":{"; ';
|
|
426
|
+
put ' do i=1 to &numcols; ';
|
|
427
|
+
put ' name=quote(trim(symget(cats(''name'',i)))); ';
|
|
428
|
+
put ' format=quote(trim(symget(cats(''fmt'',i)))); ';
|
|
429
|
+
put ' label=quote(trim(symget(cats(''label'',i)))); ';
|
|
430
|
+
put ' length=quote(trim(symget(cats(''length'',i)))); ';
|
|
431
|
+
put ' type=quote(trim(symget(cats(''typelong'',i)))); ';
|
|
432
|
+
put ' if i>1 then put "," @@; ';
|
|
433
|
+
put ' put name '':{"format":'' format '',"label":'' label ';
|
|
434
|
+
put ' '',"length":'' length '',"type":'' type ''}''; ';
|
|
435
|
+
put ' end; ';
|
|
436
|
+
put ' put ''}}''; ';
|
|
404
437
|
put ' run; ';
|
|
405
438
|
put ' %end; ';
|
|
406
439
|
put '%end; ';
|
|
407
440
|
put ' ';
|
|
408
441
|
put '%else %if &action=CLOSE %then %do; ';
|
|
409
|
-
put ' data _null_;file &jref encoding=''utf-8'' mod ; ';
|
|
442
|
+
put ' data _null_; file &jref encoding=''utf-8'' mod ; ';
|
|
410
443
|
put ' put "}"; ';
|
|
411
444
|
put ' run; ';
|
|
412
445
|
put '%end; ';
|
|
413
446
|
put '%mend mp_jsonout; ';
|
|
414
|
-
put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y
|
|
447
|
+
put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y,missing=NULL ';
|
|
448
|
+
put ' ,showmeta=NO ';
|
|
449
|
+
put '); ';
|
|
415
450
|
put '%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name ';
|
|
416
451
|
put ' sasjs_tables SYS_JES_JOB_URI; ';
|
|
417
452
|
put '%if %index("&_debug",log) %then %let _debug=131; ';
|
|
@@ -533,12 +568,13 @@ data _null_;
|
|
|
533
568
|
put ' ';
|
|
534
569
|
put ' /* setup json */ ';
|
|
535
570
|
put ' data _null_;file &fref; ';
|
|
536
|
-
put ' put ''{"
|
|
571
|
+
put ' put ''{"SYSDATE" : "'' "&SYSDATE" ''"''; ';
|
|
572
|
+
put ' put '',"SYSTIME" : "'' "&SYSTIME" ''"''; ';
|
|
537
573
|
put ' run; ';
|
|
538
574
|
put '%end; ';
|
|
539
575
|
put '%else %if &action=ARR or &action=OBJ %then %do; ';
|
|
540
576
|
put ' %mp_jsonout(&action,&ds,dslabel=&dslabel,fmt=&fmt ';
|
|
541
|
-
put ' ,jref=&fref,engine=DATASTEP,
|
|
577
|
+
put ' ,jref=&fref,engine=DATASTEP,missing=&missing,showmeta=&showmeta ';
|
|
542
578
|
put ' ) ';
|
|
543
579
|
put '%end; ';
|
|
544
580
|
put '%else %if &action=CLOSE %then %do; ';
|
|
@@ -558,9 +594,6 @@ data _null_;
|
|
|
558
594
|
put ' data _null_; file &fref mod; put ",""WORK"":{"; ';
|
|
559
595
|
put ' %do i=1 %to &wtcnt; ';
|
|
560
596
|
put ' %let wt=&&wt&i; ';
|
|
561
|
-
put ' proc contents noprint data=&wt ';
|
|
562
|
-
put ' out=_data_ (keep=name type length format:); ';
|
|
563
|
-
put ' run;%let tempds=%scan(&syslast,2,.); ';
|
|
564
597
|
put ' data _null_; file &fref mod; ';
|
|
565
598
|
put ' dsid=open("WORK.&wt",''is''); ';
|
|
566
599
|
put ' nlobs=attrn(dsid,''NLOBS''); ';
|
|
@@ -570,8 +603,7 @@ data _null_;
|
|
|
570
603
|
put ' put " ""&wt"" : {"; ';
|
|
571
604
|
put ' put ''"nlobs":'' nlobs; ';
|
|
572
605
|
put ' put '',"nvars":'' nvars; ';
|
|
573
|
-
put ' %mp_jsonout(OBJ,&
|
|
574
|
-
put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP) ';
|
|
606
|
+
put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,showmeta=YES) ';
|
|
575
607
|
put ' data _null_; file &fref mod;put "}"; ';
|
|
576
608
|
put ' %end; ';
|
|
577
609
|
put ' data _null_; file &fref mod;put "}";run; ';
|
|
@@ -596,6 +628,9 @@ data _null_;
|
|
|
596
628
|
put ' put '',"SYSVLONG" : '' sysvlong; ';
|
|
597
629
|
put ' put ",""SYSWARNINGTEXT"" : ""&syswarningtext"" "; ';
|
|
598
630
|
put ' put '',"END_DTTM" : "'' "%sysfunc(datetime(),datetime20.3)" ''" ''; ';
|
|
631
|
+
put ' memsize="%sysfunc(INPUTN(%sysfunc(getoption(memsize)), best.),sizekmg.)"; ';
|
|
632
|
+
put ' memsize=quote(cats(memsize)); ';
|
|
633
|
+
put ' put '',"MEMSIZE" : '' memsize; ';
|
|
599
634
|
put ' put "}"; ';
|
|
600
635
|
put ' ';
|
|
601
636
|
put ' %if %upcase(&fref) ne _WEBOUT and &stream=Y %then %do; ';
|
|
@@ -629,8 +664,10 @@ data _null_;
|
|
|
629
664
|
put '%global __program _program;';
|
|
630
665
|
put '%let _program=%sysfunc(coalescec(&__program,&_program));';
|
|
631
666
|
put ' ';
|
|
632
|
-
put '%macro webout(action,ds,dslabel=,fmt=);';
|
|
633
|
-
put ' %mv_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt
|
|
667
|
+
put '%macro webout(action,ds,dslabel=,fmt=,missing=NULL,showmeta=NO);';
|
|
668
|
+
put ' %mv_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt,missing=&missing';
|
|
669
|
+
put ' ,showmeta=&showmeta';
|
|
670
|
+
put ' )';
|
|
634
671
|
put '%mend;';
|
|
635
672
|
run;
|
|
636
673
|
|
package/viya/mv_webout.sas
CHANGED
|
@@ -20,13 +20,19 @@
|
|
|
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"`)
|
|
32
|
+
@param [in] showmeta= (NO) Set to YES to output metadata alongside each table,
|
|
33
|
+
such as the column formats and types. The metadata is contained inside an
|
|
34
|
+
object with the same name as the table but prefixed with a dollar sign - ie,
|
|
35
|
+
`,"$tablename":{"formats":{"col1":"$CHAR1"},"types":{"COL1":"C"}}`
|
|
30
36
|
|
|
31
37
|
<h4> SAS Macros </h4>
|
|
32
38
|
@li mp_jsonout.sas
|
|
@@ -36,7 +42,9 @@
|
|
|
36
42
|
@author Allan Bowe, source: https://github.com/sasjs/core
|
|
37
43
|
|
|
38
44
|
**/
|
|
39
|
-
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y
|
|
45
|
+
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y,missing=NULL
|
|
46
|
+
,showmeta=NO
|
|
47
|
+
);
|
|
40
48
|
%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name
|
|
41
49
|
sasjs_tables SYS_JES_JOB_URI;
|
|
42
50
|
%if %index("&_debug",log) %then %let _debug=131;
|
|
@@ -158,12 +166,13 @@
|
|
|
158
166
|
|
|
159
167
|
/* setup json */
|
|
160
168
|
data _null_;file &fref;
|
|
161
|
-
put '{"
|
|
169
|
+
put '{"SYSDATE" : "' "&SYSDATE" '"';
|
|
170
|
+
put ',"SYSTIME" : "' "&SYSTIME" '"';
|
|
162
171
|
run;
|
|
163
172
|
%end;
|
|
164
173
|
%else %if &action=ARR or &action=OBJ %then %do;
|
|
165
174
|
%mp_jsonout(&action,&ds,dslabel=&dslabel,fmt=&fmt
|
|
166
|
-
,jref=&fref,engine=DATASTEP,
|
|
175
|
+
,jref=&fref,engine=DATASTEP,missing=&missing,showmeta=&showmeta
|
|
167
176
|
)
|
|
168
177
|
%end;
|
|
169
178
|
%else %if &action=CLOSE %then %do;
|
|
@@ -183,9 +192,6 @@
|
|
|
183
192
|
data _null_; file &fref mod; put ",""WORK"":{";
|
|
184
193
|
%do i=1 %to &wtcnt;
|
|
185
194
|
%let wt=&&wt&i;
|
|
186
|
-
proc contents noprint data=&wt
|
|
187
|
-
out=_data_ (keep=name type length format:);
|
|
188
|
-
run;%let tempds=%scan(&syslast,2,.);
|
|
189
195
|
data _null_; file &fref mod;
|
|
190
196
|
dsid=open("WORK.&wt",'is');
|
|
191
197
|
nlobs=attrn(dsid,'NLOBS');
|
|
@@ -195,8 +201,7 @@
|
|
|
195
201
|
put " ""&wt"" : {";
|
|
196
202
|
put '"nlobs":' nlobs;
|
|
197
203
|
put ',"nvars":' nvars;
|
|
198
|
-
%mp_jsonout(OBJ,&
|
|
199
|
-
%mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP)
|
|
204
|
+
%mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,showmeta=YES)
|
|
200
205
|
data _null_; file &fref mod;put "}";
|
|
201
206
|
%end;
|
|
202
207
|
data _null_; file &fref mod;put "}";run;
|
|
@@ -221,6 +226,9 @@
|
|
|
221
226
|
put ',"SYSVLONG" : ' sysvlong;
|
|
222
227
|
put ",""SYSWARNINGTEXT"" : ""&syswarningtext"" ";
|
|
223
228
|
put ',"END_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '" ';
|
|
229
|
+
memsize="%sysfunc(INPUTN(%sysfunc(getoption(memsize)), best.),sizekmg.)";
|
|
230
|
+
memsize=quote(cats(memsize));
|
|
231
|
+
put ',"MEMSIZE" : ' memsize;
|
|
224
232
|
put "}";
|
|
225
233
|
|
|
226
234
|
%if %upcase(&fref) ne _WEBOUT and &stream=Y %then %do;
|