@sasjs/core 4.35.1 → 4.35.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/mp_jsonout.sas +78 -35
- package/meta/mm_createwebservice.sas +79 -36
- package/meta/mm_webout.sas +6 -2
- package/package.json +1 -1
- package/server/ms_createwebservice.sas +79 -36
- package/server/ms_webout.sas +2 -2
- package/viya/mv_createwebservice.sas +79 -36
- package/viya/mv_webout.sas +6 -2
package/base/mp_jsonout.sas
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
193
|
-
|
|
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
|
+
MAX num length=3
|
|
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 max);
|
|
223
|
+
select &fmtlist;
|
|
224
|
+
run;
|
|
225
|
+
proc sql;
|
|
226
|
+
insert into &tmpds2 select distinct fmtname,max from &tmpds3;
|
|
227
|
+
%end;
|
|
228
|
+
|
|
229
|
+
proc sql;
|
|
230
|
+
create table &tmpds4 as
|
|
231
|
+
select a.*, b.max 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
|
-
|
|
260
|
+
&&name&i=&&newname&i
|
|
199
261
|
%end;
|
|
200
262
|
));
|
|
201
263
|
&stmt_obs;
|
|
202
|
-
|
|
203
|
-
|
|
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
|
|
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
|
|
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
|
|
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 '
|
|
216
|
-
put '
|
|
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 ' MAX num length=3 ';
|
|
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 max); ';
|
|
246
|
+
put ' select &fmtlist; ';
|
|
247
|
+
put ' run; ';
|
|
248
|
+
put ' proc sql; ';
|
|
249
|
+
put ' insert into &tmpds2 select distinct fmtname,max from &tmpds3; ';
|
|
250
|
+
put ' %end; ';
|
|
251
|
+
put ' ';
|
|
252
|
+
put ' proc sql; ';
|
|
253
|
+
put ' create table &tmpds4 as ';
|
|
254
|
+
put ' select a.*, b.max 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 '
|
|
283
|
+
put ' &&name&i=&&newname&i ';
|
|
222
284
|
put ' %end; ';
|
|
223
285
|
put ' )); ';
|
|
224
286
|
put ' &stmt_obs; ';
|
|
225
|
-
put '
|
|
226
|
-
put '
|
|
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
|
|
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,7 +446,7 @@ 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=
|
|
449
|
+
put '%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=N,missing=NULL ';
|
|
407
450
|
put ' ,showmeta=N,maxobs=MAX ';
|
|
408
451
|
put '); ';
|
|
409
452
|
put '%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug ';
|
package/meta/mm_webout.sas
CHANGED
|
@@ -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=(
|
|
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"`)
|
|
@@ -40,11 +40,15 @@
|
|
|
40
40
|
<h4> SAS Macros </h4>
|
|
41
41
|
@li mp_jsonout.sas
|
|
42
42
|
|
|
43
|
+
<h4> Related Macros </h4>
|
|
44
|
+
@li ms_webout.sas
|
|
45
|
+
@li mv_webout.sas
|
|
46
|
+
|
|
43
47
|
@version 9.3
|
|
44
48
|
@author Allan Bowe
|
|
45
49
|
|
|
46
50
|
**/
|
|
47
|
-
%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=
|
|
51
|
+
%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=N,missing=NULL
|
|
48
52
|
,showmeta=N,maxobs=MAX
|
|
49
53
|
);
|
|
50
54
|
%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug
|
package/package.json
CHANGED
|
@@ -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
|
|
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
|
|
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 '
|
|
217
|
-
put '
|
|
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 ' MAX num length=3 ';
|
|
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 max); ';
|
|
247
|
+
put ' select &fmtlist; ';
|
|
248
|
+
put ' run; ';
|
|
249
|
+
put ' proc sql; ';
|
|
250
|
+
put ' insert into &tmpds2 select distinct fmtname,max from &tmpds3; ';
|
|
251
|
+
put ' %end; ';
|
|
252
|
+
put ' ';
|
|
253
|
+
put ' proc sql; ';
|
|
254
|
+
put ' create table &tmpds4 as ';
|
|
255
|
+
put ' select a.*, b.max 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 '
|
|
284
|
+
put ' &&name&i=&&newname&i ';
|
|
223
285
|
put ' %end; ';
|
|
224
286
|
put ' )); ';
|
|
225
287
|
put ' &stmt_obs; ';
|
|
226
|
-
put '
|
|
227
|
-
put '
|
|
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
|
|
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,7 +448,7 @@ 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=
|
|
451
|
+
put '%macro ms_webout(action,ds,dslabel=,fref=_webout,fmt=N,missing=NULL ';
|
|
409
452
|
put ' ,showmeta=N,maxobs=MAX ';
|
|
410
453
|
put '); ';
|
|
411
454
|
put '%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug ';
|
package/server/ms_webout.sas
CHANGED
|
@@ -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= (
|
|
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"`)
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
|
|
49
49
|
**/
|
|
50
50
|
|
|
51
|
-
%macro ms_webout(action,ds,dslabel=,fref=_webout,fmt=
|
|
51
|
+
%macro ms_webout(action,ds,dslabel=,fref=_webout,fmt=N,missing=NULL
|
|
52
52
|
,showmeta=N,maxobs=MAX
|
|
53
53
|
);
|
|
54
54
|
%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug
|
|
@@ -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
|
|
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
|
|
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 '
|
|
359
|
-
put '
|
|
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 ' MAX num length=3 ';
|
|
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 max); ';
|
|
389
|
+
put ' select &fmtlist; ';
|
|
390
|
+
put ' run; ';
|
|
391
|
+
put ' proc sql; ';
|
|
392
|
+
put ' insert into &tmpds2 select distinct fmtname,max from &tmpds3; ';
|
|
393
|
+
put ' %end; ';
|
|
394
|
+
put ' ';
|
|
395
|
+
put ' proc sql; ';
|
|
396
|
+
put ' create table &tmpds4 as ';
|
|
397
|
+
put ' select a.*, b.max 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 '
|
|
426
|
+
put ' &&name&i=&&newname&i ';
|
|
365
427
|
put ' %end; ';
|
|
366
428
|
put ' )); ';
|
|
367
429
|
put ' &stmt_obs; ';
|
|
368
|
-
put '
|
|
369
|
-
put '
|
|
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
|
|
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,7 +589,7 @@ 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=
|
|
592
|
+
put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=N,stream=Y,missing=NULL ';
|
|
550
593
|
put ' ,showmeta=N,maxobs=MAX ';
|
|
551
594
|
put '); ';
|
|
552
595
|
put '%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name ';
|
package/viya/mv_webout.sas
CHANGED
|
@@ -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=(
|
|
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"`)
|
|
@@ -40,11 +40,15 @@
|
|
|
40
40
|
@li mp_jsonout.sas
|
|
41
41
|
@li mf_getuser.sas
|
|
42
42
|
|
|
43
|
+
<h4> Related Macros </h4>
|
|
44
|
+
@li ms_webout.sas
|
|
45
|
+
@li mm_webout.sas
|
|
46
|
+
|
|
43
47
|
@version Viya 3.3
|
|
44
48
|
@author Allan Bowe, source: https://github.com/sasjs/core
|
|
45
49
|
|
|
46
50
|
**/
|
|
47
|
-
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=
|
|
51
|
+
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=N,stream=Y,missing=NULL
|
|
48
52
|
,showmeta=N,maxobs=MAX
|
|
49
53
|
);
|
|
50
54
|
%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name
|