@sasjs/core 4.35.1 → 4.35.4

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.
@@ -62,7 +62,7 @@
62
62
  @param [in] maxobs= (MAX) Provide an integer to limit the number of input rows
63
63
  that should be converted to JSON
64
64
 
65
- <h4> Related Macros </h4>
65
+ <h4> Related Files </h4>
66
66
  @li mp_ds2fmtds.sas
67
67
 
68
68
  @version 9.2
@@ -76,7 +76,8 @@
76
76
  ,showmeta=N
77
77
  ,maxobs=MAX
78
78
  )/*/STORE SOURCE*/;
79
- %local tempds colinfo fmtds i numcols stmt_obs tempvar lastobs optval;
79
+ %local tempds colinfo fmtds i numcols numobs stmt_obs lastobs optval
80
+ tmpds1 tmpds2 tmpds3 tmpds4;
80
81
  %let numcols=0;
81
82
  %if &maxobs ne MAX %then %let stmt_obs=%str(if _n_>&maxobs then stop;);
82
83
 
@@ -114,7 +115,7 @@
114
115
  by varnum;
115
116
  run;
116
117
  /* move meta to mac vars */
117
- data _null_;
118
+ data &colinfo;
118
119
  if _n_=1 then call symputx('numcols',nobs,'l');
119
120
  set &colinfo end=last nobs=nobs;
120
121
  name=upcase(name);
@@ -135,18 +136,17 @@
135
136
  end;
136
137
  /* 32 char unique name */
137
138
  newname='sasjs'!!substr(cats(put(md5(name),$hex32.)),1,27);
138
- maxlenv='maxlen'!!substr(cats(put(md5(name),$hex32.)),1,26);
139
139
 
140
140
  call symputx(cats('name',_n_),name,'l');
141
141
  call symputx(cats('newname',_n_),newname,'l');
142
- call symputx(cats('maxlenv',_n_),maxlenv,'l');
143
142
  call symputx(cats('length',_n_),length,'l');
144
- /* overwritten when fmt=Y */
145
- call symputx(cats('fmtlen',_n_),min(32767,ceil((length+3)*1.2)),'l');
146
143
  call symputx(cats('fmt',_n_),fmt,'l');
147
144
  call symputx(cats('type',_n_),type,'l');
148
145
  call symputx(cats('typelong',_n_),typelong,'l');
149
146
  call symputx(cats('label',_n_),coalescec(label,name),'l');
147
+ /* overwritten when fmt=Y and a custom format exists in catalog */
148
+ if typelong='num' then call symputx(cats('fmtlen',_n_),200,'l');
149
+ else call symputx(cats('fmtlen',_n_),min(32767,ceil((length+3)*1.5)),'l');
150
150
  run;
151
151
 
152
152
  %let tempds=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32);
@@ -189,30 +189,82 @@
189
189
  %end;
190
190
 
191
191
  %if &fmt=Y %then %do;
192
- %let tempvar=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32);
193
- /* need to find max length of formatted values */
192
+ /**
193
+ * Extract format definitions
194
+ * First, by getting library locations from dictionary.formats
195
+ * Then, by exporting the width using proc format
196
+ * Cannot use maxw from sashelp.vformat as not always populated
197
+ * Cannot use fmtinfo() as not supported in all flavours
198
+ */
199
+ %let tmpds1=%substr(fmtsum%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32);
200
+ %let tmpds2=%substr(cntl%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32);
201
+ %let tmpds3=%substr(cntl%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32);
202
+ %let tmpds4=%substr(col%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32);
203
+ proc sql noprint;
204
+ create table &tmpds1 as
205
+ select cats(libname,'.',memname) as fmtcat,
206
+ fmtname
207
+ from dictionary.formats
208
+ where fmttype='F' and libname is not null
209
+ and fmtname in (select format from &colinfo where format is not null)
210
+ order by 1;
211
+ create table &tmpds2(
212
+ FMTNAME char(32),
213
+ LENGTH num
214
+ );
215
+ %local catlist cat fmtlist i;
216
+ select distinct fmtcat into: catlist separated by ' ' from &tmpds1;
217
+ %do i=1 %to %sysfunc(countw(&catlist,%str( )));
218
+ %let cat=%scan(&catlist,&i,%str( ));
219
+ proc sql;
220
+ select distinct fmtname into: fmtlist separated by ' '
221
+ from &tmpds1 where fmtcat="&cat";
222
+ proc format lib=&cat cntlout=&tmpds3(keep=fmtname length);
223
+ select &fmtlist;
224
+ run;
225
+ proc sql;
226
+ insert into &tmpds2 select distinct fmtname,length from &tmpds3;
227
+ %end;
228
+
229
+ proc sql;
230
+ create table &tmpds4 as
231
+ select a.*, b.length as maxw
232
+ from &colinfo a
233
+ left join &tmpds2 b
234
+ on cats(a.format)=cats(upcase(b.fmtname))
235
+ order by a.varnum;
236
+ data _null_;
237
+ set &tmpds4;
238
+ if not missing(maxw);
239
+ call symputx(
240
+ cats('fmtlen',_n_),
241
+ /* vars need extra padding due to JSON escaping of special chars */
242
+ min(32767,ceil((max(length,maxw)+3)*1.5))
243
+ ,'l'
244
+ );
245
+ run;
246
+
247
+ /* configure varlenchk - as we are explicitly shortening the variables */
248
+ %let optval=%sysfunc(getoption(varlenchk));
249
+ options varlenchk=NOWARN;
194
250
  data _data_(compress=char);
251
+ /* shorten the new vars */
252
+ length
253
+ %do i=1 %to &numcols;
254
+ &&name&i $&&fmtlen&i
255
+ %end;
256
+ ;
195
257
  /* rename on entry */
196
258
  set &ds(rename=(
197
259
  %do i=1 %to &numcols;
198
- &&name&i=&&newname&i
260
+ &&name&i=&&newname&i
199
261
  %end;
200
262
  ));
201
263
  &stmt_obs;
202
- /* formatted values can be up to length 32767 */
203
- length
204
- %do i=1 %to &numcols;
205
- &&name&i
206
- %end;
207
- $32767;
208
- retain &tempvar
209
- %do i=1 %to &numcols;
210
- &&maxlenv&i
211
- %end;
212
- 0;
213
- drop &tempvar
264
+
265
+ drop
214
266
  %do i=1 %to &numcols;
215
- &&newname&i &&maxlenv&i
267
+ &&newname&i
216
268
  %end;
217
269
  ;
218
270
  %do i=1 %to &numcols;
@@ -222,19 +274,14 @@
222
274
  %else %do;
223
275
  &&name&i=put(&&newname&i,&&fmt&i);
224
276
  %end;
225
- /* grab max length of each value as we move down the data step */
226
- &tempvar=length(&&name&i);
227
- if &tempvar>&&maxlenv&i then &&maxlenv&i=&tempvar;
228
- %end;
229
- if _n_=&lastobs then do;
230
- /* add a 20% buffer in case of special chars that need to be escaped */
231
- %do i=1 %to &numcols;
232
- call symputx("fmtlen&i",min(32767,ceil((&&maxlenv&i+3)*1.2)),'l');
233
277
  %end;
278
+ if _error_ then do;
279
+ call symputx('syscc',1012);
280
+ stop;
234
281
  end;
235
- if _error_ then call symputx('syscc',1012);
236
282
  run;
237
283
  %let fmtds=&syslast;
284
+ options varlenchk=&optval;
238
285
  %end;
239
286
 
240
287
  proc format; /* credit yabwon for special null removal */
@@ -249,9 +296,6 @@
249
296
  %end;
250
297
  other = [best.];
251
298
 
252
- /* configure varlenchk - as we are explicitly shortening the variables */
253
- %let optval=%sysfunc(getoption(varlenchk));
254
- options varlenchk=NOWARN;
255
299
  data &tempds;
256
300
  attrib _all_ label='';
257
301
  %do i=1 %to &numcols;
@@ -290,7 +334,6 @@
290
334
  %end;
291
335
  %end;
292
336
  run;
293
- options varlenchk=&optval;
294
337
 
295
338
  filename _sjs3 temp lrecl=131068 ;
296
339
  data _null_;
@@ -99,7 +99,8 @@ data _null_;
99
99
  put ' ,showmeta=N ';
100
100
  put ' ,maxobs=MAX ';
101
101
  put ')/*/STORE SOURCE*/; ';
102
- put '%local tempds colinfo fmtds i numcols stmt_obs tempvar lastobs optval; ';
102
+ put '%local tempds colinfo fmtds i numcols numobs stmt_obs lastobs optval ';
103
+ put ' tmpds1 tmpds2 tmpds3 tmpds4; ';
103
104
  put '%let numcols=0; ';
104
105
  put '%if &maxobs ne MAX %then %let stmt_obs=%str(if _n_>&maxobs then stop;); ';
105
106
  put ' ';
@@ -137,7 +138,7 @@ data _null_;
137
138
  put ' by varnum; ';
138
139
  put ' run; ';
139
140
  put ' /* move meta to mac vars */ ';
140
- put ' data _null_; ';
141
+ put ' data &colinfo; ';
141
142
  put ' if _n_=1 then call symputx(''numcols'',nobs,''l''); ';
142
143
  put ' set &colinfo end=last nobs=nobs; ';
143
144
  put ' name=upcase(name); ';
@@ -158,18 +159,17 @@ data _null_;
158
159
  put ' end; ';
159
160
  put ' /* 32 char unique name */ ';
160
161
  put ' newname=''sasjs''!!substr(cats(put(md5(name),$hex32.)),1,27); ';
161
- put ' maxlenv=''maxlen''!!substr(cats(put(md5(name),$hex32.)),1,26); ';
162
162
  put ' ';
163
163
  put ' call symputx(cats(''name'',_n_),name,''l''); ';
164
164
  put ' call symputx(cats(''newname'',_n_),newname,''l''); ';
165
- put ' call symputx(cats(''maxlenv'',_n_),maxlenv,''l''); ';
166
165
  put ' call symputx(cats(''length'',_n_),length,''l''); ';
167
- put ' /* overwritten when fmt=Y */ ';
168
- put ' call symputx(cats(''fmtlen'',_n_),min(32767,ceil((length+3)*1.2)),''l''); ';
169
166
  put ' call symputx(cats(''fmt'',_n_),fmt,''l''); ';
170
167
  put ' call symputx(cats(''type'',_n_),type,''l''); ';
171
168
  put ' call symputx(cats(''typelong'',_n_),typelong,''l''); ';
172
169
  put ' call symputx(cats(''label'',_n_),coalescec(label,name),''l''); ';
170
+ put ' /* overwritten when fmt=Y and a custom format exists in catalog */ ';
171
+ put ' if typelong=''num'' then call symputx(cats(''fmtlen'',_n_),200,''l''); ';
172
+ put ' else call symputx(cats(''fmtlen'',_n_),min(32767,ceil((length+3)*1.5)),''l''); ';
173
173
  put ' run; ';
174
174
  put ' ';
175
175
  put ' %let tempds=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
@@ -212,30 +212,82 @@ data _null_;
212
212
  put ' %end; ';
213
213
  put ' ';
214
214
  put ' %if &fmt=Y %then %do; ';
215
- put ' %let tempvar=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
216
- put ' /* need to find max length of formatted values */ ';
215
+ put ' /** ';
216
+ put ' * Extract format definitions ';
217
+ put ' * First, by getting library locations from dictionary.formats ';
218
+ put ' * Then, by exporting the width using proc format ';
219
+ put ' * Cannot use maxw from sashelp.vformat as not always populated ';
220
+ put ' * Cannot use fmtinfo() as not supported in all flavours ';
221
+ put ' */ ';
222
+ put ' %let tmpds1=%substr(fmtsum%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
223
+ put ' %let tmpds2=%substr(cntl%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
224
+ put ' %let tmpds3=%substr(cntl%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
225
+ put ' %let tmpds4=%substr(col%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
226
+ put ' proc sql noprint; ';
227
+ put ' create table &tmpds1 as ';
228
+ put ' select cats(libname,''.'',memname) as fmtcat, ';
229
+ put ' fmtname ';
230
+ put ' from dictionary.formats ';
231
+ put ' where fmttype=''F'' and libname is not null ';
232
+ put ' and fmtname in (select format from &colinfo where format is not null) ';
233
+ put ' order by 1; ';
234
+ put ' create table &tmpds2( ';
235
+ put ' FMTNAME char(32), ';
236
+ put ' LENGTH num ';
237
+ put ' ); ';
238
+ put ' %local catlist cat fmtlist i; ';
239
+ put ' select distinct fmtcat into: catlist separated by '' '' from &tmpds1; ';
240
+ put ' %do i=1 %to %sysfunc(countw(&catlist,%str( ))); ';
241
+ put ' %let cat=%scan(&catlist,&i,%str( )); ';
242
+ put ' proc sql; ';
243
+ put ' select distinct fmtname into: fmtlist separated by '' '' ';
244
+ put ' from &tmpds1 where fmtcat="&cat"; ';
245
+ put ' proc format lib=&cat cntlout=&tmpds3(keep=fmtname length); ';
246
+ put ' select &fmtlist; ';
247
+ put ' run; ';
248
+ put ' proc sql; ';
249
+ put ' insert into &tmpds2 select distinct fmtname,length from &tmpds3; ';
250
+ put ' %end; ';
251
+ put ' ';
252
+ put ' proc sql; ';
253
+ put ' create table &tmpds4 as ';
254
+ put ' select a.*, b.length as maxw ';
255
+ put ' from &colinfo a ';
256
+ put ' left join &tmpds2 b ';
257
+ put ' on cats(a.format)=cats(upcase(b.fmtname)) ';
258
+ put ' order by a.varnum; ';
259
+ put ' data _null_; ';
260
+ put ' set &tmpds4; ';
261
+ put ' if not missing(maxw); ';
262
+ put ' call symputx( ';
263
+ put ' cats(''fmtlen'',_n_), ';
264
+ put ' /* vars need extra padding due to JSON escaping of special chars */ ';
265
+ put ' min(32767,ceil((max(length,maxw)+3)*1.5)) ';
266
+ put ' ,''l'' ';
267
+ put ' ); ';
268
+ put ' run; ';
269
+ put ' ';
270
+ put ' /* configure varlenchk - as we are explicitly shortening the variables */ ';
271
+ put ' %let optval=%sysfunc(getoption(varlenchk)); ';
272
+ put ' options varlenchk=NOWARN; ';
217
273
  put ' data _data_(compress=char); ';
274
+ put ' /* shorten the new vars */ ';
275
+ put ' length ';
276
+ put ' %do i=1 %to &numcols; ';
277
+ put ' &&name&i $&&fmtlen&i ';
278
+ put ' %end; ';
279
+ put ' ; ';
218
280
  put ' /* rename on entry */ ';
219
281
  put ' set &ds(rename=( ';
220
282
  put ' %do i=1 %to &numcols; ';
221
- put ' &&name&i=&&newname&i ';
283
+ put ' &&name&i=&&newname&i ';
222
284
  put ' %end; ';
223
285
  put ' )); ';
224
286
  put ' &stmt_obs; ';
225
- put ' /* formatted values can be up to length 32767 */ ';
226
- put ' length ';
227
- put ' %do i=1 %to &numcols; ';
228
- put ' &&name&i ';
229
- put ' %end; ';
230
- put ' $32767; ';
231
- put ' retain &tempvar ';
232
- put ' %do i=1 %to &numcols; ';
233
- put ' &&maxlenv&i ';
234
- put ' %end; ';
235
- put ' 0; ';
236
- put ' drop &tempvar ';
287
+ put ' ';
288
+ put ' drop ';
237
289
  put ' %do i=1 %to &numcols; ';
238
- put ' &&newname&i &&maxlenv&i ';
290
+ put ' &&newname&i ';
239
291
  put ' %end; ';
240
292
  put ' ; ';
241
293
  put ' %do i=1 %to &numcols; ';
@@ -245,19 +297,14 @@ data _null_;
245
297
  put ' %else %do; ';
246
298
  put ' &&name&i=put(&&newname&i,&&fmt&i); ';
247
299
  put ' %end; ';
248
- put ' /* grab max length of each value as we move down the data step */ ';
249
- put ' &tempvar=length(&&name&i); ';
250
- put ' if &tempvar>&&maxlenv&i then &&maxlenv&i=&tempvar; ';
251
- put ' %end; ';
252
- put ' if _n_=&lastobs then do; ';
253
- put ' /* add a 20% buffer in case of special chars that need to be escaped */ ';
254
- put ' %do i=1 %to &numcols; ';
255
- put ' call symputx("fmtlen&i",min(32767,ceil((&&maxlenv&i+3)*1.2)),''l''); ';
256
300
  put ' %end; ';
301
+ put ' if _error_ then do; ';
302
+ put ' call symputx(''syscc'',1012); ';
303
+ put ' stop; ';
257
304
  put ' end; ';
258
- put ' if _error_ then call symputx(''syscc'',1012); ';
259
305
  put ' run; ';
260
306
  put ' %let fmtds=&syslast; ';
307
+ put ' options varlenchk=&optval; ';
261
308
  put ' %end; ';
262
309
  put ' ';
263
310
  put ' proc format; /* credit yabwon for special null removal */ ';
@@ -272,9 +319,6 @@ data _null_;
272
319
  put ' %end; ';
273
320
  put ' other = [best.]; ';
274
321
  put ' ';
275
- put ' /* configure varlenchk - as we are explicitly shortening the variables */ ';
276
- put ' %let optval=%sysfunc(getoption(varlenchk)); ';
277
- put ' options varlenchk=NOWARN; ';
278
322
  put ' data &tempds; ';
279
323
  put ' attrib _all_ label=''''; ';
280
324
  put ' %do i=1 %to &numcols; ';
@@ -313,7 +357,6 @@ data _null_;
313
357
  put ' %end; ';
314
358
  put ' %end; ';
315
359
  put ' run; ';
316
- put ' options varlenchk=&optval; ';
317
360
  put ' ';
318
361
  put ' filename _sjs3 temp lrecl=131068 ; ';
319
362
  put ' data _null_; ';
@@ -403,8 +446,8 @@ data _null_;
403
446
  put ' %quote(&user) ';
404
447
  put ' ';
405
448
  put '%mend mf_getuser; ';
406
- put '%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y,missing=NULL ';
407
- put ' ,showmeta=N,maxobs=MAX ';
449
+ put '%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=N,missing=NULL ';
450
+ put ' ,showmeta=N,maxobs=MAX,workobs=0 ';
408
451
  put '); ';
409
452
  put '%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug ';
410
453
  put ' sasjs_tables; ';
@@ -477,8 +520,8 @@ data _null_;
477
520
  put '%else %if &action=CLOSE %then %do; ';
478
521
  put ' /* To avoid issues with _webout on EBI we use a temporary file */ ';
479
522
  put ' filename _sjsref temp lrecl=131068; ';
480
- put ' %if %str(&_debug) ge 131 %then %do; ';
481
- put ' /* if debug mode, send back first 10 records of each work table also */ ';
523
+ put ' %if %str(&workobs) > 0 %then %do; ';
524
+ put ' /* if debug mode, send back first XX records of each work table also */ ';
482
525
  put ' data;run;%let tempds=%scan(&syslast,2,.); ';
483
526
  put ' ods output Members=&tempds; ';
484
527
  put ' proc datasets library=WORK memtype=data; ';
@@ -502,7 +545,9 @@ data _null_;
502
545
  put ' put " ""&wt"" : {"; ';
503
546
  put ' put ''"nlobs":'' nlobs; ';
504
547
  put ' put '',"nvars":'' nvars; ';
505
- put ' %mp_jsonout(OBJ,&wt,jref=_sjsref,dslabel=first10rows,showmeta=Y,maxobs=10) ';
548
+ put ' %mp_jsonout(OBJ,&wt,jref=_sjsref,dslabel=first10rows,showmeta=Y,maxobs=10 ';
549
+ put ' ,maxobs=&workobs ';
550
+ put ' ) ';
506
551
  put ' data _null_; file _sjsref mod encoding=''utf-8''; ';
507
552
  put ' put "}"; ';
508
553
  put ' %end; ';
@@ -26,7 +26,7 @@
26
26
  @param [in] action Either FETCH, OPEN, ARR, OBJ or CLOSE
27
27
  @param [in] ds The dataset to send back to the frontend
28
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
29
+ @param [in] fmt= (N) Setting Y converts all vars to their formatted values
30
30
  @param [out] fref= (_webout) The fileref to which to write the JSON
31
31
  @param [in] missing= (NULL) Special numeric missing values can be sent as NULL
32
32
  (eg `null`) or as STRING values (eg `".a"` or `".b"`)
@@ -34,18 +34,25 @@
34
34
  such as the column formats and types. The metadata is contained inside an
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
+ @param [in] workobs= (0) When set to a positive integer, will create a new
38
+ output object (WORK) which contains this number of observations from all
39
+ tables in the WORK library.
37
40
  @param [in] maxobs= (MAX) Provide an integer to limit the number of input rows
38
41
  that should be converted to output JSON
39
42
 
40
43
  <h4> SAS Macros </h4>
41
44
  @li mp_jsonout.sas
42
45
 
46
+ <h4> Related Macros </h4>
47
+ @li ms_webout.sas
48
+ @li mv_webout.sas
49
+
43
50
  @version 9.3
44
51
  @author Allan Bowe
45
52
 
46
53
  **/
47
- %macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y,missing=NULL
48
- ,showmeta=N,maxobs=MAX
54
+ %macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=N,missing=NULL
55
+ ,showmeta=N,maxobs=MAX,workobs=0
49
56
  );
50
57
  %global _webin_file_count _webin_fileref1 _webin_name1 _program _debug
51
58
  sasjs_tables;
@@ -118,8 +125,8 @@
118
125
  %else %if &action=CLOSE %then %do;
119
126
  /* To avoid issues with _webout on EBI we use a temporary file */
120
127
  filename _sjsref temp lrecl=131068;
121
- %if %str(&_debug) ge 131 %then %do;
122
- /* if debug mode, send back first 10 records of each work table also */
128
+ %if %str(&workobs) > 0 %then %do;
129
+ /* if debug mode, send back first XX records of each work table also */
123
130
  data;run;%let tempds=%scan(&syslast,2,.);
124
131
  ods output Members=&tempds;
125
132
  proc datasets library=WORK memtype=data;
@@ -143,7 +150,9 @@
143
150
  put " ""&wt"" : {";
144
151
  put '"nlobs":' nlobs;
145
152
  put ',"nvars":' nvars;
146
- %mp_jsonout(OBJ,&wt,jref=_sjsref,dslabel=first10rows,showmeta=Y,maxobs=10)
153
+ %mp_jsonout(OBJ,&wt,jref=_sjsref,dslabel=first10rows,showmeta=Y,maxobs=10
154
+ ,maxobs=&workobs
155
+ )
147
156
  data _null_; file _sjsref mod encoding='utf-8';
148
157
  put "}";
149
158
  %end;
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "3.13.0"
37
37
  },
38
- "version": "4.35.1"
38
+ "version": "4.35.4"
39
39
  }
@@ -100,7 +100,8 @@ data _null_;
100
100
  put ' ,showmeta=N ';
101
101
  put ' ,maxobs=MAX ';
102
102
  put ')/*/STORE SOURCE*/; ';
103
- put '%local tempds colinfo fmtds i numcols stmt_obs tempvar lastobs optval; ';
103
+ put '%local tempds colinfo fmtds i numcols numobs stmt_obs lastobs optval ';
104
+ put ' tmpds1 tmpds2 tmpds3 tmpds4; ';
104
105
  put '%let numcols=0; ';
105
106
  put '%if &maxobs ne MAX %then %let stmt_obs=%str(if _n_>&maxobs then stop;); ';
106
107
  put ' ';
@@ -138,7 +139,7 @@ data _null_;
138
139
  put ' by varnum; ';
139
140
  put ' run; ';
140
141
  put ' /* move meta to mac vars */ ';
141
- put ' data _null_; ';
142
+ put ' data &colinfo; ';
142
143
  put ' if _n_=1 then call symputx(''numcols'',nobs,''l''); ';
143
144
  put ' set &colinfo end=last nobs=nobs; ';
144
145
  put ' name=upcase(name); ';
@@ -159,18 +160,17 @@ data _null_;
159
160
  put ' end; ';
160
161
  put ' /* 32 char unique name */ ';
161
162
  put ' newname=''sasjs''!!substr(cats(put(md5(name),$hex32.)),1,27); ';
162
- put ' maxlenv=''maxlen''!!substr(cats(put(md5(name),$hex32.)),1,26); ';
163
163
  put ' ';
164
164
  put ' call symputx(cats(''name'',_n_),name,''l''); ';
165
165
  put ' call symputx(cats(''newname'',_n_),newname,''l''); ';
166
- put ' call symputx(cats(''maxlenv'',_n_),maxlenv,''l''); ';
167
166
  put ' call symputx(cats(''length'',_n_),length,''l''); ';
168
- put ' /* overwritten when fmt=Y */ ';
169
- put ' call symputx(cats(''fmtlen'',_n_),min(32767,ceil((length+3)*1.2)),''l''); ';
170
167
  put ' call symputx(cats(''fmt'',_n_),fmt,''l''); ';
171
168
  put ' call symputx(cats(''type'',_n_),type,''l''); ';
172
169
  put ' call symputx(cats(''typelong'',_n_),typelong,''l''); ';
173
170
  put ' call symputx(cats(''label'',_n_),coalescec(label,name),''l''); ';
171
+ put ' /* overwritten when fmt=Y and a custom format exists in catalog */ ';
172
+ put ' if typelong=''num'' then call symputx(cats(''fmtlen'',_n_),200,''l''); ';
173
+ put ' else call symputx(cats(''fmtlen'',_n_),min(32767,ceil((length+3)*1.5)),''l''); ';
174
174
  put ' run; ';
175
175
  put ' ';
176
176
  put ' %let tempds=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
@@ -213,30 +213,82 @@ data _null_;
213
213
  put ' %end; ';
214
214
  put ' ';
215
215
  put ' %if &fmt=Y %then %do; ';
216
- put ' %let tempvar=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
217
- put ' /* need to find max length of formatted values */ ';
216
+ put ' /** ';
217
+ put ' * Extract format definitions ';
218
+ put ' * First, by getting library locations from dictionary.formats ';
219
+ put ' * Then, by exporting the width using proc format ';
220
+ put ' * Cannot use maxw from sashelp.vformat as not always populated ';
221
+ put ' * Cannot use fmtinfo() as not supported in all flavours ';
222
+ put ' */ ';
223
+ put ' %let tmpds1=%substr(fmtsum%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
224
+ put ' %let tmpds2=%substr(cntl%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
225
+ put ' %let tmpds3=%substr(cntl%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
226
+ put ' %let tmpds4=%substr(col%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
227
+ put ' proc sql noprint; ';
228
+ put ' create table &tmpds1 as ';
229
+ put ' select cats(libname,''.'',memname) as fmtcat, ';
230
+ put ' fmtname ';
231
+ put ' from dictionary.formats ';
232
+ put ' where fmttype=''F'' and libname is not null ';
233
+ put ' and fmtname in (select format from &colinfo where format is not null) ';
234
+ put ' order by 1; ';
235
+ put ' create table &tmpds2( ';
236
+ put ' FMTNAME char(32), ';
237
+ put ' LENGTH num ';
238
+ put ' ); ';
239
+ put ' %local catlist cat fmtlist i; ';
240
+ put ' select distinct fmtcat into: catlist separated by '' '' from &tmpds1; ';
241
+ put ' %do i=1 %to %sysfunc(countw(&catlist,%str( ))); ';
242
+ put ' %let cat=%scan(&catlist,&i,%str( )); ';
243
+ put ' proc sql; ';
244
+ put ' select distinct fmtname into: fmtlist separated by '' '' ';
245
+ put ' from &tmpds1 where fmtcat="&cat"; ';
246
+ put ' proc format lib=&cat cntlout=&tmpds3(keep=fmtname length); ';
247
+ put ' select &fmtlist; ';
248
+ put ' run; ';
249
+ put ' proc sql; ';
250
+ put ' insert into &tmpds2 select distinct fmtname,length from &tmpds3; ';
251
+ put ' %end; ';
252
+ put ' ';
253
+ put ' proc sql; ';
254
+ put ' create table &tmpds4 as ';
255
+ put ' select a.*, b.length as maxw ';
256
+ put ' from &colinfo a ';
257
+ put ' left join &tmpds2 b ';
258
+ put ' on cats(a.format)=cats(upcase(b.fmtname)) ';
259
+ put ' order by a.varnum; ';
260
+ put ' data _null_; ';
261
+ put ' set &tmpds4; ';
262
+ put ' if not missing(maxw); ';
263
+ put ' call symputx( ';
264
+ put ' cats(''fmtlen'',_n_), ';
265
+ put ' /* vars need extra padding due to JSON escaping of special chars */ ';
266
+ put ' min(32767,ceil((max(length,maxw)+3)*1.5)) ';
267
+ put ' ,''l'' ';
268
+ put ' ); ';
269
+ put ' run; ';
270
+ put ' ';
271
+ put ' /* configure varlenchk - as we are explicitly shortening the variables */ ';
272
+ put ' %let optval=%sysfunc(getoption(varlenchk)); ';
273
+ put ' options varlenchk=NOWARN; ';
218
274
  put ' data _data_(compress=char); ';
275
+ put ' /* shorten the new vars */ ';
276
+ put ' length ';
277
+ put ' %do i=1 %to &numcols; ';
278
+ put ' &&name&i $&&fmtlen&i ';
279
+ put ' %end; ';
280
+ put ' ; ';
219
281
  put ' /* rename on entry */ ';
220
282
  put ' set &ds(rename=( ';
221
283
  put ' %do i=1 %to &numcols; ';
222
- put ' &&name&i=&&newname&i ';
284
+ put ' &&name&i=&&newname&i ';
223
285
  put ' %end; ';
224
286
  put ' )); ';
225
287
  put ' &stmt_obs; ';
226
- put ' /* formatted values can be up to length 32767 */ ';
227
- put ' length ';
228
- put ' %do i=1 %to &numcols; ';
229
- put ' &&name&i ';
230
- put ' %end; ';
231
- put ' $32767; ';
232
- put ' retain &tempvar ';
233
- put ' %do i=1 %to &numcols; ';
234
- put ' &&maxlenv&i ';
235
- put ' %end; ';
236
- put ' 0; ';
237
- put ' drop &tempvar ';
288
+ put ' ';
289
+ put ' drop ';
238
290
  put ' %do i=1 %to &numcols; ';
239
- put ' &&newname&i &&maxlenv&i ';
291
+ put ' &&newname&i ';
240
292
  put ' %end; ';
241
293
  put ' ; ';
242
294
  put ' %do i=1 %to &numcols; ';
@@ -246,19 +298,14 @@ data _null_;
246
298
  put ' %else %do; ';
247
299
  put ' &&name&i=put(&&newname&i,&&fmt&i); ';
248
300
  put ' %end; ';
249
- put ' /* grab max length of each value as we move down the data step */ ';
250
- put ' &tempvar=length(&&name&i); ';
251
- put ' if &tempvar>&&maxlenv&i then &&maxlenv&i=&tempvar; ';
252
- put ' %end; ';
253
- put ' if _n_=&lastobs then do; ';
254
- put ' /* add a 20% buffer in case of special chars that need to be escaped */ ';
255
- put ' %do i=1 %to &numcols; ';
256
- put ' call symputx("fmtlen&i",min(32767,ceil((&&maxlenv&i+3)*1.2)),''l''); ';
257
301
  put ' %end; ';
302
+ put ' if _error_ then do; ';
303
+ put ' call symputx(''syscc'',1012); ';
304
+ put ' stop; ';
258
305
  put ' end; ';
259
- put ' if _error_ then call symputx(''syscc'',1012); ';
260
306
  put ' run; ';
261
307
  put ' %let fmtds=&syslast; ';
308
+ put ' options varlenchk=&optval; ';
262
309
  put ' %end; ';
263
310
  put ' ';
264
311
  put ' proc format; /* credit yabwon for special null removal */ ';
@@ -273,9 +320,6 @@ data _null_;
273
320
  put ' %end; ';
274
321
  put ' other = [best.]; ';
275
322
  put ' ';
276
- put ' /* configure varlenchk - as we are explicitly shortening the variables */ ';
277
- put ' %let optval=%sysfunc(getoption(varlenchk)); ';
278
- put ' options varlenchk=NOWARN; ';
279
323
  put ' data &tempds; ';
280
324
  put ' attrib _all_ label=''''; ';
281
325
  put ' %do i=1 %to &numcols; ';
@@ -314,7 +358,6 @@ data _null_;
314
358
  put ' %end; ';
315
359
  put ' %end; ';
316
360
  put ' run; ';
317
- put ' options varlenchk=&optval; ';
318
361
  put ' ';
319
362
  put ' filename _sjs3 temp lrecl=131068 ; ';
320
363
  put ' data _null_; ';
@@ -405,8 +448,8 @@ data _null_;
405
448
  put ' ';
406
449
  put '%mend mf_getuser; ';
407
450
  put ' ';
408
- put '%macro ms_webout(action,ds,dslabel=,fref=_webout,fmt=Y,missing=NULL ';
409
- put ' ,showmeta=N,maxobs=MAX ';
451
+ put '%macro ms_webout(action,ds,dslabel=,fref=_webout,fmt=N,missing=NULL ';
452
+ put ' ,showmeta=N,maxobs=MAX,workobs=0 ';
410
453
  put '); ';
411
454
  put '%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug ';
412
455
  put ' sasjs_tables; ';
@@ -469,8 +512,8 @@ data _null_;
469
512
  put ' ) ';
470
513
  put '%end; ';
471
514
  put '%else %if &action=CLOSE %then %do; ';
472
- put ' %if %str(&_debug) ge 131 %then %do; ';
473
- put ' /* if debug mode, send back first 10 records of each work table also */ ';
515
+ put ' %if %str(&workobs) > 0 %then %do; ';
516
+ put ' /* if debug mode, send back first XX records of each work table also */ ';
474
517
  put ' data;run;%let tempds=%scan(&syslast,2,.); ';
475
518
  put ' ods output Members=&tempds; ';
476
519
  put ' proc datasets library=WORK memtype=data; ';
@@ -495,7 +538,9 @@ data _null_;
495
538
  put ' put " ""&wt"" : {"; ';
496
539
  put ' put ''"nlobs":'' nlobs; ';
497
540
  put ' put '',"nvars":'' nvars; ';
498
- put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,showmeta=Y,maxobs=10) ';
541
+ put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,showmeta=Y,maxobs=10 ';
542
+ put ' ,maxobs=&workobs ';
543
+ put ' ) ';
499
544
  put ' data _null_; file &fref mod encoding=''utf-8'' termstr=lf; ';
500
545
  put ' put "}"; ';
501
546
  put ' %end; ';
@@ -23,7 +23,7 @@
23
23
  @param [in] action Either FETCH, OPEN, ARR, OBJ or CLOSE
24
24
  @param [in] ds The dataset to send back to the frontend
25
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
26
+ @param [in] fmt= (N) Setting Y converts all vars to their formatted values
27
27
  @param [out] fref= (_webout) The fileref to which to write the JSON
28
28
  @param [in] missing= (NULL) Special numeric missing values can be sent as NULL
29
29
  (eg `null`) or as STRING values (eg `".a"` or `".b"`)
@@ -31,6 +31,9 @@
31
31
  such as the column formats and types. The metadata is contained inside an
32
32
  object with the same name as the table but prefixed with a dollar sign - ie,
33
33
  `,"$tablename":{"formats":{"col1":"$CHAR1"},"types":{"COL1":"C"}}`
34
+ @param [in] workobs= (0) When set to a positive integer, will create a new
35
+ output object (WORK) which contains this number of observations from all
36
+ tables in the WORK library.
34
37
  @param [in] maxobs= (MAX) Provide an integer to limit the number of input rows
35
38
  that should be converted to output JSON
36
39
 
@@ -48,8 +51,8 @@
48
51
 
49
52
  **/
50
53
 
51
- %macro ms_webout(action,ds,dslabel=,fref=_webout,fmt=Y,missing=NULL
52
- ,showmeta=N,maxobs=MAX
54
+ %macro ms_webout(action,ds,dslabel=,fref=_webout,fmt=N,missing=NULL
55
+ ,showmeta=N,maxobs=MAX,workobs=0
53
56
  );
54
57
  %global _webin_file_count _webin_fileref1 _webin_name1 _program _debug
55
58
  sasjs_tables;
@@ -112,8 +115,8 @@
112
115
  )
113
116
  %end;
114
117
  %else %if &action=CLOSE %then %do;
115
- %if %str(&_debug) ge 131 %then %do;
116
- /* if debug mode, send back first 10 records of each work table also */
118
+ %if %str(&workobs) > 0 %then %do;
119
+ /* if debug mode, send back first XX records of each work table also */
117
120
  data;run;%let tempds=%scan(&syslast,2,.);
118
121
  ods output Members=&tempds;
119
122
  proc datasets library=WORK memtype=data;
@@ -138,7 +141,9 @@
138
141
  put " ""&wt"" : {";
139
142
  put '"nlobs":' nlobs;
140
143
  put ',"nvars":' nvars;
141
- %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,showmeta=Y,maxobs=10)
144
+ %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,showmeta=Y,maxobs=10
145
+ ,maxobs=&workobs
146
+ )
142
147
  data _null_; file &fref mod encoding='utf-8' termstr=lf;
143
148
  put "}";
144
149
  %end;
@@ -242,7 +242,8 @@ data _null_;
242
242
  put ' ,showmeta=N ';
243
243
  put ' ,maxobs=MAX ';
244
244
  put ')/*/STORE SOURCE*/; ';
245
- put '%local tempds colinfo fmtds i numcols stmt_obs tempvar lastobs optval; ';
245
+ put '%local tempds colinfo fmtds i numcols numobs stmt_obs lastobs optval ';
246
+ put ' tmpds1 tmpds2 tmpds3 tmpds4; ';
246
247
  put '%let numcols=0; ';
247
248
  put '%if &maxobs ne MAX %then %let stmt_obs=%str(if _n_>&maxobs then stop;); ';
248
249
  put ' ';
@@ -280,7 +281,7 @@ data _null_;
280
281
  put ' by varnum; ';
281
282
  put ' run; ';
282
283
  put ' /* move meta to mac vars */ ';
283
- put ' data _null_; ';
284
+ put ' data &colinfo; ';
284
285
  put ' if _n_=1 then call symputx(''numcols'',nobs,''l''); ';
285
286
  put ' set &colinfo end=last nobs=nobs; ';
286
287
  put ' name=upcase(name); ';
@@ -301,18 +302,17 @@ data _null_;
301
302
  put ' end; ';
302
303
  put ' /* 32 char unique name */ ';
303
304
  put ' newname=''sasjs''!!substr(cats(put(md5(name),$hex32.)),1,27); ';
304
- put ' maxlenv=''maxlen''!!substr(cats(put(md5(name),$hex32.)),1,26); ';
305
305
  put ' ';
306
306
  put ' call symputx(cats(''name'',_n_),name,''l''); ';
307
307
  put ' call symputx(cats(''newname'',_n_),newname,''l''); ';
308
- put ' call symputx(cats(''maxlenv'',_n_),maxlenv,''l''); ';
309
308
  put ' call symputx(cats(''length'',_n_),length,''l''); ';
310
- put ' /* overwritten when fmt=Y */ ';
311
- put ' call symputx(cats(''fmtlen'',_n_),min(32767,ceil((length+3)*1.2)),''l''); ';
312
309
  put ' call symputx(cats(''fmt'',_n_),fmt,''l''); ';
313
310
  put ' call symputx(cats(''type'',_n_),type,''l''); ';
314
311
  put ' call symputx(cats(''typelong'',_n_),typelong,''l''); ';
315
312
  put ' call symputx(cats(''label'',_n_),coalescec(label,name),''l''); ';
313
+ put ' /* overwritten when fmt=Y and a custom format exists in catalog */ ';
314
+ put ' if typelong=''num'' then call symputx(cats(''fmtlen'',_n_),200,''l''); ';
315
+ put ' else call symputx(cats(''fmtlen'',_n_),min(32767,ceil((length+3)*1.5)),''l''); ';
316
316
  put ' run; ';
317
317
  put ' ';
318
318
  put ' %let tempds=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
@@ -355,30 +355,82 @@ data _null_;
355
355
  put ' %end; ';
356
356
  put ' ';
357
357
  put ' %if &fmt=Y %then %do; ';
358
- put ' %let tempvar=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
359
- put ' /* need to find max length of formatted values */ ';
358
+ put ' /** ';
359
+ put ' * Extract format definitions ';
360
+ put ' * First, by getting library locations from dictionary.formats ';
361
+ put ' * Then, by exporting the width using proc format ';
362
+ put ' * Cannot use maxw from sashelp.vformat as not always populated ';
363
+ put ' * Cannot use fmtinfo() as not supported in all flavours ';
364
+ put ' */ ';
365
+ put ' %let tmpds1=%substr(fmtsum%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
366
+ put ' %let tmpds2=%substr(cntl%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
367
+ put ' %let tmpds3=%substr(cntl%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
368
+ put ' %let tmpds4=%substr(col%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
369
+ put ' proc sql noprint; ';
370
+ put ' create table &tmpds1 as ';
371
+ put ' select cats(libname,''.'',memname) as fmtcat, ';
372
+ put ' fmtname ';
373
+ put ' from dictionary.formats ';
374
+ put ' where fmttype=''F'' and libname is not null ';
375
+ put ' and fmtname in (select format from &colinfo where format is not null) ';
376
+ put ' order by 1; ';
377
+ put ' create table &tmpds2( ';
378
+ put ' FMTNAME char(32), ';
379
+ put ' LENGTH num ';
380
+ put ' ); ';
381
+ put ' %local catlist cat fmtlist i; ';
382
+ put ' select distinct fmtcat into: catlist separated by '' '' from &tmpds1; ';
383
+ put ' %do i=1 %to %sysfunc(countw(&catlist,%str( ))); ';
384
+ put ' %let cat=%scan(&catlist,&i,%str( )); ';
385
+ put ' proc sql; ';
386
+ put ' select distinct fmtname into: fmtlist separated by '' '' ';
387
+ put ' from &tmpds1 where fmtcat="&cat"; ';
388
+ put ' proc format lib=&cat cntlout=&tmpds3(keep=fmtname length); ';
389
+ put ' select &fmtlist; ';
390
+ put ' run; ';
391
+ put ' proc sql; ';
392
+ put ' insert into &tmpds2 select distinct fmtname,length from &tmpds3; ';
393
+ put ' %end; ';
394
+ put ' ';
395
+ put ' proc sql; ';
396
+ put ' create table &tmpds4 as ';
397
+ put ' select a.*, b.length as maxw ';
398
+ put ' from &colinfo a ';
399
+ put ' left join &tmpds2 b ';
400
+ put ' on cats(a.format)=cats(upcase(b.fmtname)) ';
401
+ put ' order by a.varnum; ';
402
+ put ' data _null_; ';
403
+ put ' set &tmpds4; ';
404
+ put ' if not missing(maxw); ';
405
+ put ' call symputx( ';
406
+ put ' cats(''fmtlen'',_n_), ';
407
+ put ' /* vars need extra padding due to JSON escaping of special chars */ ';
408
+ put ' min(32767,ceil((max(length,maxw)+3)*1.5)) ';
409
+ put ' ,''l'' ';
410
+ put ' ); ';
411
+ put ' run; ';
412
+ put ' ';
413
+ put ' /* configure varlenchk - as we are explicitly shortening the variables */ ';
414
+ put ' %let optval=%sysfunc(getoption(varlenchk)); ';
415
+ put ' options varlenchk=NOWARN; ';
360
416
  put ' data _data_(compress=char); ';
417
+ put ' /* shorten the new vars */ ';
418
+ put ' length ';
419
+ put ' %do i=1 %to &numcols; ';
420
+ put ' &&name&i $&&fmtlen&i ';
421
+ put ' %end; ';
422
+ put ' ; ';
361
423
  put ' /* rename on entry */ ';
362
424
  put ' set &ds(rename=( ';
363
425
  put ' %do i=1 %to &numcols; ';
364
- put ' &&name&i=&&newname&i ';
426
+ put ' &&name&i=&&newname&i ';
365
427
  put ' %end; ';
366
428
  put ' )); ';
367
429
  put ' &stmt_obs; ';
368
- put ' /* formatted values can be up to length 32767 */ ';
369
- put ' length ';
370
- put ' %do i=1 %to &numcols; ';
371
- put ' &&name&i ';
372
- put ' %end; ';
373
- put ' $32767; ';
374
- put ' retain &tempvar ';
375
- put ' %do i=1 %to &numcols; ';
376
- put ' &&maxlenv&i ';
377
- put ' %end; ';
378
- put ' 0; ';
379
- put ' drop &tempvar ';
430
+ put ' ';
431
+ put ' drop ';
380
432
  put ' %do i=1 %to &numcols; ';
381
- put ' &&newname&i &&maxlenv&i ';
433
+ put ' &&newname&i ';
382
434
  put ' %end; ';
383
435
  put ' ; ';
384
436
  put ' %do i=1 %to &numcols; ';
@@ -388,19 +440,14 @@ data _null_;
388
440
  put ' %else %do; ';
389
441
  put ' &&name&i=put(&&newname&i,&&fmt&i); ';
390
442
  put ' %end; ';
391
- put ' /* grab max length of each value as we move down the data step */ ';
392
- put ' &tempvar=length(&&name&i); ';
393
- put ' if &tempvar>&&maxlenv&i then &&maxlenv&i=&tempvar; ';
394
- put ' %end; ';
395
- put ' if _n_=&lastobs then do; ';
396
- put ' /* add a 20% buffer in case of special chars that need to be escaped */ ';
397
- put ' %do i=1 %to &numcols; ';
398
- put ' call symputx("fmtlen&i",min(32767,ceil((&&maxlenv&i+3)*1.2)),''l''); ';
399
443
  put ' %end; ';
444
+ put ' if _error_ then do; ';
445
+ put ' call symputx(''syscc'',1012); ';
446
+ put ' stop; ';
400
447
  put ' end; ';
401
- put ' if _error_ then call symputx(''syscc'',1012); ';
402
448
  put ' run; ';
403
449
  put ' %let fmtds=&syslast; ';
450
+ put ' options varlenchk=&optval; ';
404
451
  put ' %end; ';
405
452
  put ' ';
406
453
  put ' proc format; /* credit yabwon for special null removal */ ';
@@ -415,9 +462,6 @@ data _null_;
415
462
  put ' %end; ';
416
463
  put ' other = [best.]; ';
417
464
  put ' ';
418
- put ' /* configure varlenchk - as we are explicitly shortening the variables */ ';
419
- put ' %let optval=%sysfunc(getoption(varlenchk)); ';
420
- put ' options varlenchk=NOWARN; ';
421
465
  put ' data &tempds; ';
422
466
  put ' attrib _all_ label=''''; ';
423
467
  put ' %do i=1 %to &numcols; ';
@@ -456,7 +500,6 @@ data _null_;
456
500
  put ' %end; ';
457
501
  put ' %end; ';
458
502
  put ' run; ';
459
- put ' options varlenchk=&optval; ';
460
503
  put ' ';
461
504
  put ' filename _sjs3 temp lrecl=131068 ; ';
462
505
  put ' data _null_; ';
@@ -546,8 +589,8 @@ data _null_;
546
589
  put ' %quote(&user) ';
547
590
  put ' ';
548
591
  put '%mend mf_getuser; ';
549
- put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y,missing=NULL ';
550
- put ' ,showmeta=N,maxobs=MAX ';
592
+ put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=N,stream=Y,missing=NULL ';
593
+ put ' ,showmeta=N,maxobs=MAX,workobs=0 ';
551
594
  put '); ';
552
595
  put '%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name ';
553
596
  put ' sasjs_tables SYS_JES_JOB_URI; ';
@@ -654,8 +697,8 @@ data _null_;
654
697
  put ' ) ';
655
698
  put '%end; ';
656
699
  put '%else %if &action=CLOSE %then %do; ';
657
- put ' %if %str(&_debug) ge 131 %then %do; ';
658
- put ' /* send back first 10 records of each work table for debugging */ ';
700
+ put ' %if %str(&workobs) > 0 %then %do; ';
701
+ put ' /* send back first XX records of each work table for debugging */ ';
659
702
  put ' data;run;%let tempds=%scan(&syslast,2,.); ';
660
703
  put ' ods output Members=&tempds; ';
661
704
  put ' proc datasets library=WORK memtype=data; ';
@@ -678,7 +721,9 @@ data _null_;
678
721
  put ' put " ""&wt"" : {"; ';
679
722
  put ' put ''"nlobs":'' nlobs; ';
680
723
  put ' put '',"nvars":'' nvars; ';
681
- put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,showmeta=Y,maxobs=10) ';
724
+ put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,showmeta=Y ';
725
+ put ' ,maxobs=&workobs ';
726
+ put ' ) ';
682
727
  put ' data _null_; file &fref mod;put "}"; ';
683
728
  put ' %end; ';
684
729
  put ' data _null_; file &fref mod;put "}";run; ';
@@ -25,7 +25,7 @@
25
25
  @param [in] _webout= fileref for returning the json
26
26
  @param [out] fref=(_mvwtemp) Temp fileref to which to write the output
27
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
28
+ @param [in] fmt= (N) Setting Y converts all vars to their formatted values
29
29
  @param [in] stream=(Y) Change to N if not streaming to _webout
30
30
  @param [in] missing= (NULL) Special numeric missing values can be sent as NULL
31
31
  (eg `null`) or as STRING values (eg `".a"` or `".b"`)
@@ -35,17 +35,24 @@
35
35
  `,"$tablename":{"formats":{"col1":"$CHAR1"},"types":{"COL1":"C"}}`
36
36
  @param [in] maxobs= (MAX) Provide an integer to limit the number of input rows
37
37
  that should be converted to output JSON
38
+ @param [in] workobs= (0) When set to a positive integer, will create a new
39
+ output object (WORK) which contains this number of observations from all
40
+ tables in the WORK library.
38
41
 
39
42
  <h4> SAS Macros </h4>
40
43
  @li mp_jsonout.sas
41
44
  @li mf_getuser.sas
42
45
 
46
+ <h4> Related Macros </h4>
47
+ @li ms_webout.sas
48
+ @li mm_webout.sas
49
+
43
50
  @version Viya 3.3
44
51
  @author Allan Bowe, source: https://github.com/sasjs/core
45
52
 
46
53
  **/
47
- %macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y,stream=Y,missing=NULL
48
- ,showmeta=N,maxobs=MAX
54
+ %macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=N,stream=Y,missing=NULL
55
+ ,showmeta=N,maxobs=MAX,workobs=0
49
56
  );
50
57
  %global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name
51
58
  sasjs_tables SYS_JES_JOB_URI;
@@ -152,8 +159,8 @@
152
159
  )
153
160
  %end;
154
161
  %else %if &action=CLOSE %then %do;
155
- %if %str(&_debug) ge 131 %then %do;
156
- /* send back first 10 records of each work table for debugging */
162
+ %if %str(&workobs) > 0 %then %do;
163
+ /* send back first XX records of each work table for debugging */
157
164
  data;run;%let tempds=%scan(&syslast,2,.);
158
165
  ods output Members=&tempds;
159
166
  proc datasets library=WORK memtype=data;
@@ -176,7 +183,9 @@
176
183
  put " ""&wt"" : {";
177
184
  put '"nlobs":' nlobs;
178
185
  put ',"nvars":' nvars;
179
- %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,showmeta=Y,maxobs=10)
186
+ %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,showmeta=Y
187
+ ,maxobs=&workobs
188
+ )
180
189
  data _null_; file &fref mod;put "}";
181
190
  %end;
182
191
  data _null_; file &fref mod;put "}";run;