mirror of
https://github.com/sasjs/core.git
synced 2025-12-10 14:04:36 +00:00
fix: performance optimisations. closes #295
This commit is contained in:
@@ -236,14 +236,13 @@ data _null_;
|
||||
file &adapter;
|
||||
put "/* Created on %sysfunc(datetime(),datetime19.) by &sysuserid */";
|
||||
/* WEBOUT BEGIN */
|
||||
put ' ';
|
||||
put '%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y ';
|
||||
put ' ,engine=DATASTEP ';
|
||||
put ' ,missing=NULL ';
|
||||
put ' ,showmeta=N ';
|
||||
put ' ,maxobs=MAX ';
|
||||
put ')/*/STORE SOURCE*/; ';
|
||||
put '%local tempds colinfo fmtds i numcols stmt_obs; ';
|
||||
put '%local tempds colinfo fmtds i numcols stmt_obs tempvar lastobs optval; ';
|
||||
put '%let numcols=0; ';
|
||||
put '%if &maxobs ne MAX %then %let stmt_obs=%str(if _n_>&maxobs then stop;); ';
|
||||
put ' ';
|
||||
@@ -302,10 +301,14 @@ data _null_;
|
||||
put ' end; ';
|
||||
put ' /* 32 char unique name */ ';
|
||||
put ' newname=''sasjs''!!substr(cats(put(md5(name),$hex32.)),1,27); ';
|
||||
put ' maxlenv=''maxlen''!!substr(cats(put(md5(name),$hex32.)),1,26); ';
|
||||
put ' ';
|
||||
put ' call symputx(cats(''name'',_n_),name,''l''); ';
|
||||
put ' call symputx(cats(''newname'',_n_),newname,''l''); ';
|
||||
put ' call symputx(cats(''maxlenv'',_n_),maxlenv,''l''); ';
|
||||
put ' call symputx(cats(''length'',_n_),length,''l''); ';
|
||||
put ' /* overwritten when fmt=Y */ ';
|
||||
put ' call symputx(cats(''fmtlen'',_n_),min(32767,ceil((length+3)*1.2)),''l''); ';
|
||||
put ' call symputx(cats(''fmt'',_n_),fmt,''l''); ';
|
||||
put ' call symputx(cats(''type'',_n_),type,''l''); ';
|
||||
put ' call symputx(cats(''typelong'',_n_),typelong,''l''); ';
|
||||
@@ -313,6 +316,9 @@ data _null_;
|
||||
put ' run; ';
|
||||
put ' ';
|
||||
put ' %let tempds=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
|
||||
put ' proc sql; ';
|
||||
put ' select count(*) into: lastobs from &ds; ';
|
||||
put ' %if &maxobs ne MAX %then %let lastobs=%sysfunc(min(&lastobs,&maxobs)); ';
|
||||
put ' ';
|
||||
put ' %if &engine=PROCJSON %then %do; ';
|
||||
put ' %if &missing=STRING %then %do; ';
|
||||
@@ -349,24 +355,49 @@ data _null_;
|
||||
put ' %end; ';
|
||||
put ' ';
|
||||
put ' %if &fmt=Y %then %do; ';
|
||||
put ' data _data_; ';
|
||||
put ' %let tempvar=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
|
||||
put ' /* need to find max length of formatted values */ ';
|
||||
put ' data _data_(compress=char); ';
|
||||
put ' /* rename on entry */ ';
|
||||
put ' set &ds(rename=( ';
|
||||
put ' %do i=1 %to &numcols; ';
|
||||
put ' &&name&i=&&newname&i ';
|
||||
put ' %end; ';
|
||||
put ' )); ';
|
||||
put ' &stmt_obs; ';
|
||||
put ' /* formatted values can be up to length 32767 */ ';
|
||||
put ' length ';
|
||||
put ' %do i=1 %to &numcols; ';
|
||||
put ' &&name&i ';
|
||||
put ' %end; ';
|
||||
put ' $32767; ';
|
||||
put ' retain &tempvar ';
|
||||
put ' %do i=1 %to &numcols; ';
|
||||
put ' &&maxlenv&i ';
|
||||
put ' %end; ';
|
||||
put ' 0; ';
|
||||
put ' drop &tempvar ';
|
||||
put ' %do i=1 %to &numcols; ';
|
||||
put ' &&newname&i &&maxlenv&i ';
|
||||
put ' %end; ';
|
||||
put ' ; ';
|
||||
put ' %do i=1 %to &numcols; ';
|
||||
put ' /* formatted values can be up to length 32767 */ ';
|
||||
put ' length &&name&i $32767; ';
|
||||
put ' %if &&typelong&i=num %then %do; ';
|
||||
put ' &&name&i=left(put(&&newname&i,&&fmt&i)); ';
|
||||
put ' &&name&i=cats(put(&&newname&i,&&fmt&i)); ';
|
||||
put ' %end; ';
|
||||
put ' %else %do; ';
|
||||
put ' &&name&i=put(&&newname&i,&&fmt&i); ';
|
||||
put ' %end; ';
|
||||
put ' drop &&newname&i; ';
|
||||
put ' /* grab max length of each value as we move down the data step */ ';
|
||||
put ' &tempvar=length(&&name&i); ';
|
||||
put ' if &tempvar>&&maxlenv&i then &&maxlenv&i=&tempvar; ';
|
||||
put ' %end; ';
|
||||
put ' if _n_=&lastobs then do; ';
|
||||
put ' /* add a 20% buffer in case of special chars that need to be escaped */ ';
|
||||
put ' %do i=1 %to &numcols; ';
|
||||
put ' call symputx("fmtlen&i",min(32767,ceil((&&maxlenv&i+3)*1.2)),''l''); ';
|
||||
put ' %end; ';
|
||||
put ' end; ';
|
||||
put ' if _error_ then call symputx(''syscc'',1012); ';
|
||||
put ' run; ';
|
||||
put ' %let fmtds=&syslast; ';
|
||||
@@ -384,12 +415,15 @@ data _null_;
|
||||
put ' %end; ';
|
||||
put ' other = [best.]; ';
|
||||
put ' ';
|
||||
put ' /* configure varlenchk - as we are explicitly shortening the variables */ ';
|
||||
put ' %let optval=%sysfunc(getoption(varlenchk)); ';
|
||||
put ' options varlenchk=NOWARN; ';
|
||||
put ' data &tempds; ';
|
||||
put ' attrib _all_ label=''''; ';
|
||||
put ' %do i=1 %to &numcols; ';
|
||||
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
||||
put ' length &&name&i $32767; ';
|
||||
put ' format &&name&i $32767.; ';
|
||||
put ' length &&name&i $&&fmtlen&i...; ';
|
||||
put ' format &&name&i $&&fmtlen&i...; ';
|
||||
put ' %end; ';
|
||||
put ' %end; ';
|
||||
put ' %if &fmt=Y %then %do; ';
|
||||
@@ -422,6 +456,7 @@ data _null_;
|
||||
put ' %end; ';
|
||||
put ' %end; ';
|
||||
put ' run; ';
|
||||
put ' options varlenchk=&optval; ';
|
||||
put ' ';
|
||||
put ' filename _sjs3 temp lrecl=131068 ; ';
|
||||
put ' data _null_; ';
|
||||
|
||||
Reference in New Issue
Block a user