@sasjs/core 4.35.0 → 4.35.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/base/mp_jsonout.sas
CHANGED
|
@@ -70,14 +70,13 @@
|
|
|
70
70
|
@source https://github.com/sasjs/core
|
|
71
71
|
|
|
72
72
|
**/
|
|
73
|
-
|
|
74
73
|
%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y
|
|
75
74
|
,engine=DATASTEP
|
|
76
75
|
,missing=NULL
|
|
77
76
|
,showmeta=N
|
|
78
77
|
,maxobs=MAX
|
|
79
78
|
)/*/STORE SOURCE*/;
|
|
80
|
-
%local tempds colinfo fmtds i numcols stmt_obs;
|
|
79
|
+
%local tempds colinfo fmtds i numcols stmt_obs tempvar lastobs optval;
|
|
81
80
|
%let numcols=0;
|
|
82
81
|
%if &maxobs ne MAX %then %let stmt_obs=%str(if _n_>&maxobs then stop;);
|
|
83
82
|
|
|
@@ -136,10 +135,14 @@
|
|
|
136
135
|
end;
|
|
137
136
|
/* 32 char unique name */
|
|
138
137
|
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');
|
|
142
143
|
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');
|
|
143
146
|
call symputx(cats('fmt',_n_),fmt,'l');
|
|
144
147
|
call symputx(cats('type',_n_),type,'l');
|
|
145
148
|
call symputx(cats('typelong',_n_),typelong,'l');
|
|
@@ -147,6 +150,9 @@
|
|
|
147
150
|
run;
|
|
148
151
|
|
|
149
152
|
%let tempds=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32);
|
|
153
|
+
proc sql;
|
|
154
|
+
select count(*) into: lastobs from &ds;
|
|
155
|
+
%if &maxobs ne MAX %then %let lastobs=%sysfunc(min(&lastobs,&maxobs));
|
|
150
156
|
|
|
151
157
|
%if &engine=PROCJSON %then %do;
|
|
152
158
|
%if &missing=STRING %then %do;
|
|
@@ -183,24 +189,49 @@
|
|
|
183
189
|
%end;
|
|
184
190
|
|
|
185
191
|
%if &fmt=Y %then %do;
|
|
186
|
-
|
|
192
|
+
%let tempvar=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32);
|
|
193
|
+
/* need to find max length of formatted values */
|
|
194
|
+
data _data_(compress=char);
|
|
187
195
|
/* rename on entry */
|
|
188
196
|
set &ds(rename=(
|
|
189
197
|
%do i=1 %to &numcols;
|
|
190
198
|
&&name&i=&&newname&i
|
|
191
199
|
%end;
|
|
192
200
|
));
|
|
201
|
+
&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
|
|
214
|
+
%do i=1 %to &numcols;
|
|
215
|
+
&&newname&i &&maxlenv&i
|
|
216
|
+
%end;
|
|
217
|
+
;
|
|
193
218
|
%do i=1 %to &numcols;
|
|
194
|
-
/* formatted values can be up to length 32767 */
|
|
195
|
-
length &&name&i $32767;
|
|
196
219
|
%if &&typelong&i=num %then %do;
|
|
197
|
-
&&name&i=
|
|
220
|
+
&&name&i=cats(put(&&newname&i,&&fmt&i));
|
|
198
221
|
%end;
|
|
199
222
|
%else %do;
|
|
200
223
|
&&name&i=put(&&newname&i,&&fmt&i);
|
|
201
224
|
%end;
|
|
202
|
-
|
|
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;
|
|
203
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
|
+
%end;
|
|
234
|
+
end;
|
|
204
235
|
if _error_ then call symputx('syscc',1012);
|
|
205
236
|
run;
|
|
206
237
|
%let fmtds=&syslast;
|
|
@@ -218,12 +249,15 @@
|
|
|
218
249
|
%end;
|
|
219
250
|
other = [best.];
|
|
220
251
|
|
|
252
|
+
/* configure varlenchk - as we are explicitly shortening the variables */
|
|
253
|
+
%let optval=%sysfunc(getoption(varlenchk));
|
|
254
|
+
options varlenchk=NOWARN;
|
|
221
255
|
data &tempds;
|
|
222
256
|
attrib _all_ label='';
|
|
223
257
|
%do i=1 %to &numcols;
|
|
224
258
|
%if &&typelong&i=char or &fmt=Y %then %do;
|
|
225
|
-
length &&name&i
|
|
226
|
-
format &&name&i
|
|
259
|
+
length &&name&i $&&fmtlen&i...;
|
|
260
|
+
format &&name&i $&&fmtlen&i...;
|
|
227
261
|
%end;
|
|
228
262
|
%end;
|
|
229
263
|
%if &fmt=Y %then %do;
|
|
@@ -256,6 +290,7 @@
|
|
|
256
290
|
%end;
|
|
257
291
|
%end;
|
|
258
292
|
run;
|
|
293
|
+
options varlenchk=&optval;
|
|
259
294
|
|
|
260
295
|
filename _sjs3 temp lrecl=131068 ;
|
|
261
296
|
data _null_;
|
|
@@ -93,14 +93,13 @@ data _null_;
|
|
|
93
93
|
file sasjs lrecl=3000 ;
|
|
94
94
|
put "/* Created on %sysfunc(datetime(),datetime19.) by %mf_getuser() */";
|
|
95
95
|
/* WEBOUT BEGIN */
|
|
96
|
-
put ' ';
|
|
97
96
|
put '%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y ';
|
|
98
97
|
put ' ,engine=DATASTEP ';
|
|
99
98
|
put ' ,missing=NULL ';
|
|
100
99
|
put ' ,showmeta=N ';
|
|
101
100
|
put ' ,maxobs=MAX ';
|
|
102
101
|
put ')/*/STORE SOURCE*/; ';
|
|
103
|
-
put '%local tempds colinfo fmtds i numcols stmt_obs; ';
|
|
102
|
+
put '%local tempds colinfo fmtds i numcols stmt_obs tempvar lastobs optval; ';
|
|
104
103
|
put '%let numcols=0; ';
|
|
105
104
|
put '%if &maxobs ne MAX %then %let stmt_obs=%str(if _n_>&maxobs then stop;); ';
|
|
106
105
|
put ' ';
|
|
@@ -159,10 +158,14 @@ data _null_;
|
|
|
159
158
|
put ' end; ';
|
|
160
159
|
put ' /* 32 char unique name */ ';
|
|
161
160
|
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''); ';
|
|
165
166
|
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''); ';
|
|
166
169
|
put ' call symputx(cats(''fmt'',_n_),fmt,''l''); ';
|
|
167
170
|
put ' call symputx(cats(''type'',_n_),type,''l''); ';
|
|
168
171
|
put ' call symputx(cats(''typelong'',_n_),typelong,''l''); ';
|
|
@@ -170,6 +173,9 @@ data _null_;
|
|
|
170
173
|
put ' run; ';
|
|
171
174
|
put ' ';
|
|
172
175
|
put ' %let tempds=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
|
|
176
|
+
put ' proc sql; ';
|
|
177
|
+
put ' select count(*) into: lastobs from &ds; ';
|
|
178
|
+
put ' %if &maxobs ne MAX %then %let lastobs=%sysfunc(min(&lastobs,&maxobs)); ';
|
|
173
179
|
put ' ';
|
|
174
180
|
put ' %if &engine=PROCJSON %then %do; ';
|
|
175
181
|
put ' %if &missing=STRING %then %do; ';
|
|
@@ -206,24 +212,49 @@ data _null_;
|
|
|
206
212
|
put ' %end; ';
|
|
207
213
|
put ' ';
|
|
208
214
|
put ' %if &fmt=Y %then %do; ';
|
|
209
|
-
put '
|
|
215
|
+
put ' %let tempvar=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
|
|
216
|
+
put ' /* need to find max length of formatted values */ ';
|
|
217
|
+
put ' data _data_(compress=char); ';
|
|
210
218
|
put ' /* rename on entry */ ';
|
|
211
219
|
put ' set &ds(rename=( ';
|
|
212
220
|
put ' %do i=1 %to &numcols; ';
|
|
213
221
|
put ' &&name&i=&&newname&i ';
|
|
214
222
|
put ' %end; ';
|
|
215
223
|
put ' )); ';
|
|
224
|
+
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 ';
|
|
237
|
+
put ' %do i=1 %to &numcols; ';
|
|
238
|
+
put ' &&newname&i &&maxlenv&i ';
|
|
239
|
+
put ' %end; ';
|
|
240
|
+
put ' ; ';
|
|
216
241
|
put ' %do i=1 %to &numcols; ';
|
|
217
|
-
put ' /* formatted values can be up to length 32767 */ ';
|
|
218
|
-
put ' length &&name&i $32767; ';
|
|
219
242
|
put ' %if &&typelong&i=num %then %do; ';
|
|
220
|
-
put ' &&name&i=
|
|
243
|
+
put ' &&name&i=cats(put(&&newname&i,&&fmt&i)); ';
|
|
221
244
|
put ' %end; ';
|
|
222
245
|
put ' %else %do; ';
|
|
223
246
|
put ' &&name&i=put(&&newname&i,&&fmt&i); ';
|
|
224
247
|
put ' %end; ';
|
|
225
|
-
put '
|
|
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; ';
|
|
226
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
|
+
put ' %end; ';
|
|
257
|
+
put ' end; ';
|
|
227
258
|
put ' if _error_ then call symputx(''syscc'',1012); ';
|
|
228
259
|
put ' run; ';
|
|
229
260
|
put ' %let fmtds=&syslast; ';
|
|
@@ -241,12 +272,15 @@ data _null_;
|
|
|
241
272
|
put ' %end; ';
|
|
242
273
|
put ' other = [best.]; ';
|
|
243
274
|
put ' ';
|
|
275
|
+
put ' /* configure varlenchk - as we are explicitly shortening the variables */ ';
|
|
276
|
+
put ' %let optval=%sysfunc(getoption(varlenchk)); ';
|
|
277
|
+
put ' options varlenchk=NOWARN; ';
|
|
244
278
|
put ' data &tempds; ';
|
|
245
279
|
put ' attrib _all_ label=''''; ';
|
|
246
280
|
put ' %do i=1 %to &numcols; ';
|
|
247
281
|
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
|
248
|
-
put ' length &&name&i
|
|
249
|
-
put ' format &&name&i
|
|
282
|
+
put ' length &&name&i $&&fmtlen&i...; ';
|
|
283
|
+
put ' format &&name&i $&&fmtlen&i...; ';
|
|
250
284
|
put ' %end; ';
|
|
251
285
|
put ' %end; ';
|
|
252
286
|
put ' %if &fmt=Y %then %do; ';
|
|
@@ -279,6 +313,7 @@ data _null_;
|
|
|
279
313
|
put ' %end; ';
|
|
280
314
|
put ' %end; ';
|
|
281
315
|
put ' run; ';
|
|
316
|
+
put ' options varlenchk=&optval; ';
|
|
282
317
|
put ' ';
|
|
283
318
|
put ' filename _sjs3 temp lrecl=131068 ; ';
|
|
284
319
|
put ' data _null_; ';
|
package/package.json
CHANGED
|
@@ -94,14 +94,13 @@ data _null_;
|
|
|
94
94
|
file &sasjsref termstr=crlf lrecl=512;
|
|
95
95
|
put "/* Created on %sysfunc(datetime(),datetime19.) by %mf_getuser() */";
|
|
96
96
|
/* WEBOUT BEGIN */
|
|
97
|
-
put ' ';
|
|
98
97
|
put '%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y ';
|
|
99
98
|
put ' ,engine=DATASTEP ';
|
|
100
99
|
put ' ,missing=NULL ';
|
|
101
100
|
put ' ,showmeta=N ';
|
|
102
101
|
put ' ,maxobs=MAX ';
|
|
103
102
|
put ')/*/STORE SOURCE*/; ';
|
|
104
|
-
put '%local tempds colinfo fmtds i numcols stmt_obs; ';
|
|
103
|
+
put '%local tempds colinfo fmtds i numcols stmt_obs tempvar lastobs optval; ';
|
|
105
104
|
put '%let numcols=0; ';
|
|
106
105
|
put '%if &maxobs ne MAX %then %let stmt_obs=%str(if _n_>&maxobs then stop;); ';
|
|
107
106
|
put ' ';
|
|
@@ -160,10 +159,14 @@ data _null_;
|
|
|
160
159
|
put ' end; ';
|
|
161
160
|
put ' /* 32 char unique name */ ';
|
|
162
161
|
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''); ';
|
|
166
167
|
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''); ';
|
|
167
170
|
put ' call symputx(cats(''fmt'',_n_),fmt,''l''); ';
|
|
168
171
|
put ' call symputx(cats(''type'',_n_),type,''l''); ';
|
|
169
172
|
put ' call symputx(cats(''typelong'',_n_),typelong,''l''); ';
|
|
@@ -171,6 +174,9 @@ data _null_;
|
|
|
171
174
|
put ' run; ';
|
|
172
175
|
put ' ';
|
|
173
176
|
put ' %let tempds=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
|
|
177
|
+
put ' proc sql; ';
|
|
178
|
+
put ' select count(*) into: lastobs from &ds; ';
|
|
179
|
+
put ' %if &maxobs ne MAX %then %let lastobs=%sysfunc(min(&lastobs,&maxobs)); ';
|
|
174
180
|
put ' ';
|
|
175
181
|
put ' %if &engine=PROCJSON %then %do; ';
|
|
176
182
|
put ' %if &missing=STRING %then %do; ';
|
|
@@ -207,24 +213,49 @@ data _null_;
|
|
|
207
213
|
put ' %end; ';
|
|
208
214
|
put ' ';
|
|
209
215
|
put ' %if &fmt=Y %then %do; ';
|
|
210
|
-
put '
|
|
216
|
+
put ' %let tempvar=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
|
|
217
|
+
put ' /* need to find max length of formatted values */ ';
|
|
218
|
+
put ' data _data_(compress=char); ';
|
|
211
219
|
put ' /* rename on entry */ ';
|
|
212
220
|
put ' set &ds(rename=( ';
|
|
213
221
|
put ' %do i=1 %to &numcols; ';
|
|
214
222
|
put ' &&name&i=&&newname&i ';
|
|
215
223
|
put ' %end; ';
|
|
216
224
|
put ' )); ';
|
|
225
|
+
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 ';
|
|
238
|
+
put ' %do i=1 %to &numcols; ';
|
|
239
|
+
put ' &&newname&i &&maxlenv&i ';
|
|
240
|
+
put ' %end; ';
|
|
241
|
+
put ' ; ';
|
|
217
242
|
put ' %do i=1 %to &numcols; ';
|
|
218
|
-
put ' /* formatted values can be up to length 32767 */ ';
|
|
219
|
-
put ' length &&name&i $32767; ';
|
|
220
243
|
put ' %if &&typelong&i=num %then %do; ';
|
|
221
|
-
put ' &&name&i=
|
|
244
|
+
put ' &&name&i=cats(put(&&newname&i,&&fmt&i)); ';
|
|
222
245
|
put ' %end; ';
|
|
223
246
|
put ' %else %do; ';
|
|
224
247
|
put ' &&name&i=put(&&newname&i,&&fmt&i); ';
|
|
225
248
|
put ' %end; ';
|
|
226
|
-
put '
|
|
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; ';
|
|
227
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
|
+
put ' %end; ';
|
|
258
|
+
put ' end; ';
|
|
228
259
|
put ' if _error_ then call symputx(''syscc'',1012); ';
|
|
229
260
|
put ' run; ';
|
|
230
261
|
put ' %let fmtds=&syslast; ';
|
|
@@ -242,12 +273,15 @@ data _null_;
|
|
|
242
273
|
put ' %end; ';
|
|
243
274
|
put ' other = [best.]; ';
|
|
244
275
|
put ' ';
|
|
276
|
+
put ' /* configure varlenchk - as we are explicitly shortening the variables */ ';
|
|
277
|
+
put ' %let optval=%sysfunc(getoption(varlenchk)); ';
|
|
278
|
+
put ' options varlenchk=NOWARN; ';
|
|
245
279
|
put ' data &tempds; ';
|
|
246
280
|
put ' attrib _all_ label=''''; ';
|
|
247
281
|
put ' %do i=1 %to &numcols; ';
|
|
248
282
|
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
|
249
|
-
put ' length &&name&i
|
|
250
|
-
put ' format &&name&i
|
|
283
|
+
put ' length &&name&i $&&fmtlen&i...; ';
|
|
284
|
+
put ' format &&name&i $&&fmtlen&i...; ';
|
|
251
285
|
put ' %end; ';
|
|
252
286
|
put ' %end; ';
|
|
253
287
|
put ' %if &fmt=Y %then %do; ';
|
|
@@ -280,6 +314,7 @@ data _null_;
|
|
|
280
314
|
put ' %end; ';
|
|
281
315
|
put ' %end; ';
|
|
282
316
|
put ' run; ';
|
|
317
|
+
put ' options varlenchk=&optval; ';
|
|
283
318
|
put ' ';
|
|
284
319
|
put ' filename _sjs3 temp lrecl=131068 ; ';
|
|
285
320
|
put ' data _null_; ';
|
|
@@ -236,14 +236,13 @@ data _null_;
|
|
|
236
236
|
file &adapter;
|
|
237
237
|
put "/* Created on %sysfunc(datetime(),datetime19.) by &sysuserid */";
|
|
238
238
|
/* WEBOUT BEGIN */
|
|
239
|
-
put ' ';
|
|
240
239
|
put '%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y ';
|
|
241
240
|
put ' ,engine=DATASTEP ';
|
|
242
241
|
put ' ,missing=NULL ';
|
|
243
242
|
put ' ,showmeta=N ';
|
|
244
243
|
put ' ,maxobs=MAX ';
|
|
245
244
|
put ')/*/STORE SOURCE*/; ';
|
|
246
|
-
put '%local tempds colinfo fmtds i numcols stmt_obs; ';
|
|
245
|
+
put '%local tempds colinfo fmtds i numcols stmt_obs tempvar lastobs optval; ';
|
|
247
246
|
put '%let numcols=0; ';
|
|
248
247
|
put '%if &maxobs ne MAX %then %let stmt_obs=%str(if _n_>&maxobs then stop;); ';
|
|
249
248
|
put ' ';
|
|
@@ -302,10 +301,14 @@ data _null_;
|
|
|
302
301
|
put ' end; ';
|
|
303
302
|
put ' /* 32 char unique name */ ';
|
|
304
303
|
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''); ';
|
|
308
309
|
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''); ';
|
|
309
312
|
put ' call symputx(cats(''fmt'',_n_),fmt,''l''); ';
|
|
310
313
|
put ' call symputx(cats(''type'',_n_),type,''l''); ';
|
|
311
314
|
put ' call symputx(cats(''typelong'',_n_),typelong,''l''); ';
|
|
@@ -313,6 +316,9 @@ data _null_;
|
|
|
313
316
|
put ' run; ';
|
|
314
317
|
put ' ';
|
|
315
318
|
put ' %let tempds=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
|
|
319
|
+
put ' proc sql; ';
|
|
320
|
+
put ' select count(*) into: lastobs from &ds; ';
|
|
321
|
+
put ' %if &maxobs ne MAX %then %let lastobs=%sysfunc(min(&lastobs,&maxobs)); ';
|
|
316
322
|
put ' ';
|
|
317
323
|
put ' %if &engine=PROCJSON %then %do; ';
|
|
318
324
|
put ' %if &missing=STRING %then %do; ';
|
|
@@ -349,24 +355,49 @@ data _null_;
|
|
|
349
355
|
put ' %end; ';
|
|
350
356
|
put ' ';
|
|
351
357
|
put ' %if &fmt=Y %then %do; ';
|
|
352
|
-
put '
|
|
358
|
+
put ' %let tempvar=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
|
|
359
|
+
put ' /* need to find max length of formatted values */ ';
|
|
360
|
+
put ' data _data_(compress=char); ';
|
|
353
361
|
put ' /* rename on entry */ ';
|
|
354
362
|
put ' set &ds(rename=( ';
|
|
355
363
|
put ' %do i=1 %to &numcols; ';
|
|
356
364
|
put ' &&name&i=&&newname&i ';
|
|
357
365
|
put ' %end; ';
|
|
358
366
|
put ' )); ';
|
|
367
|
+
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 ';
|
|
380
|
+
put ' %do i=1 %to &numcols; ';
|
|
381
|
+
put ' &&newname&i &&maxlenv&i ';
|
|
382
|
+
put ' %end; ';
|
|
383
|
+
put ' ; ';
|
|
359
384
|
put ' %do i=1 %to &numcols; ';
|
|
360
|
-
put ' /* formatted values can be up to length 32767 */ ';
|
|
361
|
-
put ' length &&name&i $32767; ';
|
|
362
385
|
put ' %if &&typelong&i=num %then %do; ';
|
|
363
|
-
put ' &&name&i=
|
|
386
|
+
put ' &&name&i=cats(put(&&newname&i,&&fmt&i)); ';
|
|
364
387
|
put ' %end; ';
|
|
365
388
|
put ' %else %do; ';
|
|
366
389
|
put ' &&name&i=put(&&newname&i,&&fmt&i); ';
|
|
367
390
|
put ' %end; ';
|
|
368
|
-
put '
|
|
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; ';
|
|
369
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
|
+
put ' %end; ';
|
|
400
|
+
put ' end; ';
|
|
370
401
|
put ' if _error_ then call symputx(''syscc'',1012); ';
|
|
371
402
|
put ' run; ';
|
|
372
403
|
put ' %let fmtds=&syslast; ';
|
|
@@ -384,12 +415,15 @@ data _null_;
|
|
|
384
415
|
put ' %end; ';
|
|
385
416
|
put ' other = [best.]; ';
|
|
386
417
|
put ' ';
|
|
418
|
+
put ' /* configure varlenchk - as we are explicitly shortening the variables */ ';
|
|
419
|
+
put ' %let optval=%sysfunc(getoption(varlenchk)); ';
|
|
420
|
+
put ' options varlenchk=NOWARN; ';
|
|
387
421
|
put ' data &tempds; ';
|
|
388
422
|
put ' attrib _all_ label=''''; ';
|
|
389
423
|
put ' %do i=1 %to &numcols; ';
|
|
390
424
|
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
|
391
|
-
put ' length &&name&i
|
|
392
|
-
put ' format &&name&i
|
|
425
|
+
put ' length &&name&i $&&fmtlen&i...; ';
|
|
426
|
+
put ' format &&name&i $&&fmtlen&i...; ';
|
|
393
427
|
put ' %end; ';
|
|
394
428
|
put ' %end; ';
|
|
395
429
|
put ' %if &fmt=Y %then %do; ';
|
|
@@ -422,6 +456,7 @@ data _null_;
|
|
|
422
456
|
put ' %end; ';
|
|
423
457
|
put ' %end; ';
|
|
424
458
|
put ' run; ';
|
|
459
|
+
put ' options varlenchk=&optval; ';
|
|
425
460
|
put ' ';
|
|
426
461
|
put ' filename _sjs3 temp lrecl=131068 ; ';
|
|
427
462
|
put ' data _null_; ';
|