1
0
mirror of https://github.com/sasjs/core.git synced 2025-12-11 06:24:35 +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
<h4> SAS Macros </h4>
@li mf_getuniquename.sas
@li mf_getvarlist.sas
@li mf_getvartype.sas
@@ -4712,7 +4713,7 @@ quit;
,termstr=CRLF
)/*/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;
%put %str(WARN)ING: &ds does not exist;
@@ -4739,16 +4740,18 @@ quit;
/* first get headers */
data _null_;
file &outloc &outencoding lrecl=32767 termstr=&termstr;
length header $ 2000 varnm $32;
length header $ 2000 varnm $32 dlm $1;
dsid=open("&ds.","i");
num=attrn(dsid,"nvars");
dlm=&delim;
do i=1 to num;
varnm=upcase(varname(dsid,i));
if i=num then dlm='';
%if &headerformat=NAME %then %do;
header=cats(varnm,&delim);
header=cats(varnm,dlm);
%end;
%else %if &headerformat=LABEL %then %do;
header = cats(coalescec(varlabel(dsid,i),varnm),&delim);
header = cats(coalescec(varlabel(dsid,i),varnm),dlm);
%end;
%else %if &headerformat=SASJS %then %do;
if vartype(dsid,i)='C' then header=cats(varnm,':$char',varlen(dsid,i),'.');
@@ -4793,18 +4796,29 @@ data _null_;
%end;
%let vat=@;
%let vcom=&delim;
%let vmiss=%mf_getuniquename(prefix=csvcol3_);
/* next, export data */
data _null_;
set &ds.;
file &outloc mod dlm=&delim dsd &outencoding lrecl=32767 termstr=&termstr;
if _n_=1 then &vmiss=' ';
%do i=1 %to &vcnt;
%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;
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;
%else %do;
put &var &&vlen&i "," &vat;
put &var &&vlen&i &vcom &vat;
%end;
%end;
run;

View File

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

View File

@@ -29,11 +29,11 @@ data _null_;
input;
list;
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;
%mp_assert(
iftrue=("&test1a"="x factor,Y,Z"),
iftrue=("&test1a"="x factor, Y, Z"),
desc=Checking header row Test 1,
outds=work.test_results
)
@@ -55,11 +55,11 @@ data _null_;
input;
list;
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;
%mp_assert(
iftrue=("&test2a"="X;Y;Z"),
iftrue=("&test2a"="X; Y; Z"),
desc=Checking header row Test 2,
outds=work.test_results
)
@@ -81,7 +81,7 @@ data _null_;
input;
list;
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;
%mp_assert(

View File

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

View File

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