1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-06 17:10:05 +00:00

fix: updates following test results

This commit is contained in:
munja
2022-01-30 18:34:29 +01:00
parent 899de27617
commit 899f6d9558
5 changed files with 66 additions and 41 deletions

28
all.sas
View File

@@ -4696,6 +4696,7 @@ quit;
@li LF @li LF
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mf_getuniquename.sas
@li mf_getvarlist.sas @li mf_getvarlist.sas
@li mf_getvartype.sas @li mf_getvartype.sas
@@ -4712,7 +4713,7 @@ quit;
,termstr=CRLF ,termstr=CRLF
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%local outloc delim i varlist var vcnt vat dsv; %local outloc delim i varlist var vcnt vat dsv vcom vmiss;
%if not %sysfunc(exist(&ds)) %then %do; %if not %sysfunc(exist(&ds)) %then %do;
%put %str(WARN)ING: &ds does not exist; %put %str(WARN)ING: &ds does not exist;
@@ -4739,16 +4740,18 @@ quit;
/* first get headers */ /* first get headers */
data _null_; data _null_;
file &outloc &outencoding lrecl=32767 termstr=&termstr; file &outloc &outencoding lrecl=32767 termstr=&termstr;
length header $ 2000 varnm $32; length header $ 2000 varnm $32 dlm $1;
dsid=open("&ds.","i"); dsid=open("&ds.","i");
num=attrn(dsid,"nvars"); num=attrn(dsid,"nvars");
dlm=&delim;
do i=1 to num; do i=1 to num;
varnm=upcase(varname(dsid,i)); varnm=upcase(varname(dsid,i));
if i=num then dlm='';
%if &headerformat=NAME %then %do; %if &headerformat=NAME %then %do;
header=cats(varnm,&delim); header=cats(varnm,dlm);
%end; %end;
%else %if &headerformat=LABEL %then %do; %else %if &headerformat=LABEL %then %do;
header = cats(coalescec(varlabel(dsid,i),varnm),&delim); header = cats(coalescec(varlabel(dsid,i),varnm),dlm);
%end; %end;
%else %if &headerformat=SASJS %then %do; %else %if &headerformat=SASJS %then %do;
if vartype(dsid,i)='C' then header=cats(varnm,':$char',varlen(dsid,i),'.'); if vartype(dsid,i)='C' then header=cats(varnm,':$char',varlen(dsid,i),'.');
@@ -4793,18 +4796,29 @@ data _null_;
%end; %end;
%let vat=@; %let vat=@;
%let vcom=&delim;
%let vmiss=%mf_getuniquename(prefix=csvcol3_);
/* next, export data */ /* next, export data */
data _null_; data _null_;
set &ds.; set &ds.;
file &outloc mod dlm=&delim dsd &outencoding lrecl=32767 termstr=&termstr; file &outloc mod dlm=&delim dsd &outencoding lrecl=32767 termstr=&termstr;
if _n_=1 then &vmiss=' ';
%do i=1 %to &vcnt; %do i=1 %to &vcnt;
%let var=%scan(&varlist,&i); %let var=%scan(&varlist,&i);
%if &i=&vcnt %then %let vat=; %if &i=&vcnt %then %do;
%let vat=;
%let vcom=;
%end;
%if %mf_getvartype(&ds,&var)=N %then %do; %if %mf_getvartype(&ds,&var)=N %then %do;
put &var &vat; /* must use period - in order to work in both 9.4 and Viya 3.5 */
if missing(&var) and &var ne %sysfunc(getoption(MISSING)) then do;
&vmiss=cats('.',&var);
put &vmiss &vat;
end;
else put &var &vat;
%end; %end;
%else %do; %else %do;
put &var &&vlen&i "," &vat; put &var &&vlen&i &vcom &vat;
%end; %end;
%end; %end;
run; run;

View File

@@ -33,6 +33,7 @@
@li LF @li LF
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mf_getuniquename.sas
@li mf_getvarlist.sas @li mf_getvarlist.sas
@li mf_getvartype.sas @li mf_getvartype.sas
@@ -49,7 +50,7 @@
,termstr=CRLF ,termstr=CRLF
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%local outloc delim i varlist var vcnt vat dsv; %local outloc delim i varlist var vcnt vat dsv vcom vmiss;
%if not %sysfunc(exist(&ds)) %then %do; %if not %sysfunc(exist(&ds)) %then %do;
%put %str(WARN)ING: &ds does not exist; %put %str(WARN)ING: &ds does not exist;
@@ -76,16 +77,18 @@
/* first get headers */ /* first get headers */
data _null_; data _null_;
file &outloc &outencoding lrecl=32767 termstr=&termstr; file &outloc &outencoding lrecl=32767 termstr=&termstr;
length header $ 2000 varnm $32; length header $ 2000 varnm $32 dlm $1;
dsid=open("&ds.","i"); dsid=open("&ds.","i");
num=attrn(dsid,"nvars"); num=attrn(dsid,"nvars");
dlm=&delim;
do i=1 to num; do i=1 to num;
varnm=upcase(varname(dsid,i)); varnm=upcase(varname(dsid,i));
if i=num then dlm='';
%if &headerformat=NAME %then %do; %if &headerformat=NAME %then %do;
header=cats(varnm,&delim); header=cats(varnm,dlm);
%end; %end;
%else %if &headerformat=LABEL %then %do; %else %if &headerformat=LABEL %then %do;
header = cats(coalescec(varlabel(dsid,i),varnm),&delim); header = cats(coalescec(varlabel(dsid,i),varnm),dlm);
%end; %end;
%else %if &headerformat=SASJS %then %do; %else %if &headerformat=SASJS %then %do;
if vartype(dsid,i)='C' then header=cats(varnm,':$char',varlen(dsid,i),'.'); if vartype(dsid,i)='C' then header=cats(varnm,':$char',varlen(dsid,i),'.');
@@ -130,18 +133,29 @@ data _null_;
%end; %end;
%let vat=@; %let vat=@;
%let vcom=&delim;
%let vmiss=%mf_getuniquename(prefix=csvcol3_);
/* next, export data */ /* next, export data */
data _null_; data _null_;
set &ds.; set &ds.;
file &outloc mod dlm=&delim dsd &outencoding lrecl=32767 termstr=&termstr; file &outloc mod dlm=&delim dsd &outencoding lrecl=32767 termstr=&termstr;
if _n_=1 then &vmiss=' ';
%do i=1 %to &vcnt; %do i=1 %to &vcnt;
%let var=%scan(&varlist,&i); %let var=%scan(&varlist,&i);
%if &i=&vcnt %then %let vat=; %if &i=&vcnt %then %do;
%let vat=;
%let vcom=;
%end;
%if %mf_getvartype(&ds,&var)=N %then %do; %if %mf_getvartype(&ds,&var)=N %then %do;
put &var &vat; /* must use period - in order to work in both 9.4 and Viya 3.5 */
if missing(&var) and &var ne %sysfunc(getoption(MISSING)) then do;
&vmiss=cats('.',&var);
put &vmiss &vat;
end;
else put &var &vat;
%end; %end;
%else %do; %else %do;
put &var &&vlen&i "," &vat; put &var &&vlen&i &vcom &vat;
%end; %end;
%end; %end;
run; run;

View File

@@ -29,11 +29,11 @@ data _null_;
input; input;
list; list;
if _n_=1 then call symputx('test1a',_infile_); if _n_=1 then call symputx('test1a',_infile_);
else if _infile_='1,"t""w""o",Z' then call symputx('test1b','PASS'); else if _infile_=:'1," t""w""o",.Z' then call symputx('test1b','PASS');
run; run;
%mp_assert( %mp_assert(
iftrue=("&test1a"="x factor,Y,Z"), iftrue=("&test1a"="x factor, Y, Z"),
desc=Checking header row Test 1, desc=Checking header row Test 1,
outds=work.test_results outds=work.test_results
) )
@@ -55,11 +55,11 @@ data _null_;
input; input;
list; list;
if _n_=1 then call symputx('test2a',_infile_); if _n_=1 then call symputx('test2a',_infile_);
else if _infile_='1;"t""w""o";Z' then call symputx('test2b','PASS'); else if _infile_=:'1;" t""w""o";.Z' then call symputx('test2b','PASS');
run; run;
%mp_assert( %mp_assert(
iftrue=("&test2a"="X;Y;Z"), iftrue=("&test2a"="X; Y; Z"),
desc=Checking header row Test 2, desc=Checking header row Test 2,
outds=work.test_results outds=work.test_results
) )
@@ -81,7 +81,7 @@ data _null_;
input; input;
list; list;
if _n_=1 then call symputx('test3a',_infile_); if _n_=1 then call symputx('test3a',_infile_);
else if _infile_='1;"t""w""o";Z' then call symputx('test3b','PASS'); else if _infile_=:'1," t""w""o",.Z' then call symputx('test3b','PASS');
run; run;
%mp_assert( %mp_assert(

View File

@@ -12,15 +12,20 @@
**/ **/
filename ft15f001 temp; filename ft15f001 temp;
parmcards4; parmcards4;
%put Initialising sendObj: ;
%put _all_;
%webout(FETCH) %webout(FETCH)
%webout(OPEN) %webout(OPEN)
%macro x(); %macro x();
%do i=1 %to &_webin_file_count; %if %symexist(sasjs_tables) %then %do i=1 %to %sysfunc(countw(&sasjs_tables));
%webout(OBJ,&&_webin_name&i,missing=STRING) %let table=%scan(&sasjs_tables,&i);
%end; %webout(OBJ,&table,missing=STRING)
%end;
%else %do i=1 %to &_webin_file_count;
%webout(OBJ,&&_webin_name&i,missing=STRING)
%end;
%mend x; %x() %mend x; %x()
%webout(CLOSE) %webout(CLOSE)
;;;; ;;;;
@@ -55,24 +60,13 @@ run;
data _null_; data _null_;
infile test1; infile test1;
input; input;
if _n_=3 then do; putlog _n_ _infile_;
if _infile_=', "somedata1":' then call symputx('test1a','PASS'); if _infile_=', "somedata1":' then call symputx('test1a','PASS');
else putlog _n_= _infile_=; if _infile_='{"X":1 ,"Y":" t\"w\"o" ,"Z":"Z" }' then
end; call symputx('test1b','PASS');
else if _n_=5 then do; if _infile_='], "somedata2":' then call symputx('test1c','PASS');
if _infile_='{"X":1 ,"Y":" t\"w\"o" ,"Z":"Z" }' then if _infile_='{"X":1 ,"Y":" t\"w\"o" ,"Z":"Z" }' then
call symputx('test1b','PASS');
else putlog _n_= _infile_=;
end;
else if _n_=6 then do;
if _infile_='], "somedata2":' then call symputx('test1c','PASS');
else putlog _n_= _infile_=;
end;
else if _n_=8 then do;
if _infile_='{"X":1 ,"Y":" t\"w\"o" ,"Z":"Z" }' then
call symputx('test1d','PASS'); call symputx('test1d','PASS');
else putlog _n_= _infile_=;
end;
run; run;
%mp_assert( %mp_assert(

View File

@@ -23,4 +23,7 @@
%end; %end;
%mend loglevel; %mend loglevel;
%loglevel() %loglevel()
%put Initialised &_program;
%put _all_;