1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-11 02:50:06 +00:00

Compare commits

...

9 Commits

Author SHA1 Message Date
Allan Bowe
dae03c5730 fix: adding SYSSCPL to mp_abort and webout macros 2021-09-24 17:31:42 +01:00
Allan Bowe
14efe5d3fd chore: removing copyright notice (copy paste error) 2021-09-22 21:10:00 +01:00
Allan Bowe
653244d737 Merge pull request #75 from sasjs/mp_getcols
Mp getcols macro
2021-09-22 19:34:25 +03:00
Allan Bowe
086831b3f5 chore: updating all.sas 2021-09-22 17:20:02 +01:00
Allan Bowe
6eca585fc1 feat: new mp_getcols macro 2021-09-22 17:19:49 +01:00
Allan Bowe
f6ba36fc28 feat: adding more info to result description in mp_assertcolvals 2021-09-22 17:19:29 +01:00
Allan Bowe
7406288d79 fix: mp_gsubfile() now works with multiline files (and we have a multiline test to go with it) 2021-09-16 18:30:17 +01:00
Allan Bowe
2e7fcbe5b8 fix: prevening truncation of _debug in mp_abort.sas and more reliable way to fetch syswarningtext and syserrortext 2021-09-16 14:04:50 +01:00
Allan Bowe
3e7b9f8c14 chore: fixing example in header for mp_gsubfile() 2021-09-16 13:54:27 +01:00
16 changed files with 247 additions and 22 deletions

99
all.sas
View File

@@ -1806,7 +1806,7 @@ Usage:
/* send response in SASjs JSON format */ /* send response in SASjs JSON format */
data _null_; data _null_;
file _webout mod lrecl=32000 encoding='utf-8'; file _webout mod lrecl=32000 encoding='utf-8';
length msg $32767 debug $8; length msg $32767 ;
sasdatetime=datetime(); sasdatetime=datetime();
msg=cats(symget('msg'),'\n\nLog Extract:\n',symget('logmsg')); msg=cats(symget('msg'),'\n\nLog Extract:\n',symget('logmsg'));
/* escape the quotes */ /* escape the quotes */
@@ -1837,13 +1837,16 @@ Usage:
_PROGRAM=quote(trim(resolve(symget('_PROGRAM')))); _PROGRAM=quote(trim(resolve(symget('_PROGRAM'))));
put ',"_PROGRAM" : ' _PROGRAM ; put ',"_PROGRAM" : ' _PROGRAM ;
put ",""SYSCC"" : ""&syscc"" "; put ",""SYSCC"" : ""&syscc"" ";
put ",""SYSERRORTEXT"" : ""&syserrortext"" "; syserrortext=quote(trim(symget('syserrortext')));
put ",""SYSERRORTEXT"" : " syserrortext;
put ",""SYSHOSTNAME"" : ""&syshostname"" "; put ",""SYSHOSTNAME"" : ""&syshostname"" ";
put ",""SYSJOBID"" : ""&sysjobid"" "; put ",""SYSJOBID"" : ""&sysjobid"" ";
put ",""SYSSCPL"" : ""&sysscpl"" ";
put ",""SYSSITE"" : ""&syssite"" "; put ",""SYSSITE"" : ""&syssite"" ";
sysvlong=quote(trim(symget('sysvlong'))); sysvlong=quote(trim(symget('sysvlong')));
put ',"SYSVLONG" : ' sysvlong; put ',"SYSVLONG" : ' sysvlong;
put ",""SYSWARNINGTEXT"" : ""&syswarningtext"" "; syswarningtext=quote(trim(symget('syswarningtext')));
put ",""SYSWARNINGTEXT"" : " syswarningtext;
put ',"END_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '" '; put ',"END_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '" ';
put "}" @; put "}" @;
if debug ge '"131"' then put '>>weboutEND<<'; if debug ge '"131"' then put '>>weboutEND<<';
@@ -2214,6 +2217,14 @@ Usage:
select count(*) into: orig from &lib..&ds; select count(*) into: orig from &lib..&ds;
quit; quit;
%local notfound;
proc sql outobs=10 noprint;
select distinct &col into: notfound separated by ' '
from &lib..&ds
where &col not in (
select &ccol from &clib..&cds
);
%mp_abort(iftrue= (&syscc ne 0) %mp_abort(iftrue= (&syscc ne 0)
,mac=&sysmacroname ,mac=&sysmacroname
,msg=%str(syscc=&syscc after macro query) ,msg=%str(syscc=&syscc after macro query)
@@ -2224,7 +2235,7 @@ Usage:
test_description=symget('desc'); test_description=symget('desc');
test_result='FAIL'; test_result='FAIL';
test_comments="&sysmacroname: &lib..&ds..&col has &result values " test_comments="&sysmacroname: &lib..&ds..&col has &result values "
!!"not in &clib..&cds..&ccol "; !!"not in &clib..&cds..&ccol.. First 10 vals:"!!symget('notfound');
%if &test=ANYVAL %then %do; %if &test=ANYVAL %then %do;
if &result < &orig then test_result='PASS'; if &result < &orig then test_result='PASS';
%end; %end;
@@ -4228,6 +4239,70 @@ filename &fref1 clear;
%mend mp_filtervalidate; %mend mp_filtervalidate;
/** /**
@file
@brief Creates a dataset with column metadata.
@details This macro takes the `proc contents` output and "tidies it up" in the
following ways:
@li Blank labels are filled in with column names
@li Formats are reconstructed with default values
@li Types such as DATE / TIME / DATETIME are inferred from the formats
Example usage:
%mp_getcols(sashelp.airline,outds=work.myds)
@param ds The dataset from which to obtain column metadata
@param outds= (work.cols) The output dataset to create. Sample data:
|NAME $|LENGTH 8|VARNUM 8|LABEL $|FORMAT $49|TYPE $1 |DDTYPE $|
|---|---|---|---|---|---|---|
|AIR|8|2|international airline travel (thousands)|8.|N|NUMERIC|
|DATE|8|1|DATE|MONYY.|N|DATE|
|REGION|3|3|REGION|$3.|C|CHARACTER|
<h4> Related Macros </h4>
@li mf_getvarlist.sas
@li mm_getcols.sas
@version 9.2
@author Allan Bowe
**/
%macro mp_getcols(ds, outds=work.cols);
proc contents noprint data=&ds
out=_data_ (keep=name type length label varnum format:);
run;
data &outds(keep=name type length varnum format label ddtype);
set &syslast(rename=(format=format2 type=type2));
name=upcase(name);
if type2=2 then do;
length format $49.;
if format2='' then format=cats('$',length,'.');
else if formatl=0 then format=cats(format2,'.');
else format=cats(format2,formatl,'.');
type='C';
ddtype='CHARACTER';
end;
else do;
if format2='' then format=cats(length,'.');
else if formatl=0 then format=cats(format2,'.');
else if formatd=0 then format=cats(format2,formatl,'.');
else format=cats(format2,formatl,'.',formatd);
type='N';
if format=:'DATETIME' then ddtype='DATETIME';
else if format=:'DATE' or format=:'DDMMYY' or format=:'MMDDYY'
or format=:'YYMMDD' or format=:'E8601DA' or format=:'B8601DA'
or format=:'MONYY'
then ddtype='DATE';
else if format=:'TIME' then ddtype='TIME';
else ddtype='NUMERIC';
end;
if label='' then label=name;
run;
%mend mp_getcols;/**
@file mp_getconstraints.sas @file mp_getconstraints.sas
@brief Get constraint details at column level @brief Get constraint details at column level
@details Useful for capturing constraints before they are dropped / reapplied @details Useful for capturing constraints before they are dropped / reapplied
@@ -5108,7 +5183,7 @@ create table &outds (rename=(
file "&file"; file "&file";
put "&str"; put "&str";
run; run;
%mp_gsubfile(file=&file, pattern=str, replacement=rep) %mp_gsubfile(file=&file, patternvar=str, replacevar=rep)
data _null_; data _null_;
infile "&file"; infile "&file";
input; input;
@@ -6028,14 +6103,14 @@ select distinct lowcase(memname)
We take the standard definition one step further by embedding the informat We take the standard definition one step further by embedding the informat
in the table header row, like so: in the table header row, like so:
|var1:$|var2:best.|var3:date9.| |var1:$32|var2:best.|var3:date9.|
|---|---|---| |---|---|---|
|some text|42|01JAN1960| |some text|42|01JAN1960|
|blah|1|31DEC1999| |blah|1|31DEC1999|
Which resolves to: Which resolves to:
|var1:$|var2:best.|var3:date9.| |var1:$32|var2:best.|var3:date9.|
|---|---|---| |---|---|---|
|some text|42|01JAN1960| |some text|42|01JAN1960|
|blah|1|31DEC1999| |blah|1|31DEC1999|
@@ -9984,6 +10059,7 @@ data _null_;
put ' put ",""SYSERRORTEXT"" : ""&syserrortext"" "; '; put ' put ",""SYSERRORTEXT"" : ""&syserrortext"" "; ';
put ' put ",""SYSHOSTNAME"" : ""&syshostname"" "; '; put ' put ",""SYSHOSTNAME"" : ""&syshostname"" "; ';
put ' put ",""SYSJOBID"" : ""&sysjobid"" "; '; put ' put ",""SYSJOBID"" : ""&sysjobid"" "; ';
put ' put ",""SYSSCPL"" : ""&sysscpl"" "; ';
put ' put ",""SYSSITE"" : ""&syssite"" "; '; put ' put ",""SYSSITE"" : ""&syssite"" "; ';
put ' sysvlong=quote(trim(symget(''sysvlong''))); '; put ' sysvlong=quote(trim(symget(''sysvlong''))); ';
put ' put '',"SYSVLONG" : '' sysvlong; '; put ' put '',"SYSVLONG" : '' sysvlong; ';
@@ -13479,6 +13555,7 @@ run;
put ",""SYSERRORTEXT"" : ""&syserrortext"" "; put ",""SYSERRORTEXT"" : ""&syserrortext"" ";
put ",""SYSHOSTNAME"" : ""&syshostname"" "; put ",""SYSHOSTNAME"" : ""&syshostname"" ";
put ",""SYSJOBID"" : ""&sysjobid"" "; put ",""SYSJOBID"" : ""&sysjobid"" ";
put ",""SYSSCPL"" : ""&sysscpl"" ";
put ",""SYSSITE"" : ""&syssite"" "; put ",""SYSSITE"" : ""&syssite"" ";
sysvlong=quote(trim(symget('sysvlong'))); sysvlong=quote(trim(symget('sysvlong')));
put ',"SYSVLONG" : ' sysvlong; put ',"SYSVLONG" : ' sysvlong;
@@ -14950,6 +15027,7 @@ data _null_;
put ' put ",""SYSCC"" : ""&syscc"" "; '; put ' put ",""SYSCC"" : ""&syscc"" "; ';
put ' put ",""SYSERRORTEXT"" : ""&syserrortext"" "; '; put ' put ",""SYSERRORTEXT"" : ""&syserrortext"" "; ';
put ' put ",""SYSHOSTNAME"" : ""&syshostname"" "; '; put ' put ",""SYSHOSTNAME"" : ""&syshostname"" "; ';
put ' put ",""SYSSCPL"" : ""&sysscpl"" "; ';
put ' put ",""SYSSITE"" : ""&syssite"" "; '; put ' put ",""SYSSITE"" : ""&syssite"" "; ';
put ' sysvlong=quote(trim(symget(''sysvlong''))); '; put ' sysvlong=quote(trim(symget(''sysvlong''))); ';
put ' put '',"SYSVLONG" : '' sysvlong; '; put ' put '',"SYSVLONG" : '' sysvlong; ';
@@ -18789,6 +18867,7 @@ filename &fref1 clear;
put ",""SYSCC"" : ""&syscc"" "; put ",""SYSCC"" : ""&syscc"" ";
put ",""SYSERRORTEXT"" : ""&syserrortext"" "; put ",""SYSERRORTEXT"" : ""&syserrortext"" ";
put ",""SYSHOSTNAME"" : ""&syshostname"" "; put ",""SYSHOSTNAME"" : ""&syshostname"" ";
put ",""SYSSCPL"" : ""&sysscpl"" ";
put ",""SYSSITE"" : ""&syssite"" "; put ",""SYSSITE"" : ""&syssite"" ";
sysvlong=quote(trim(symget('sysvlong'))); sysvlong=quote(trim(symget('sysvlong')));
put ',"SYSVLONG" : ' sysvlong; put ',"SYSVLONG" : ' sysvlong;
@@ -18829,7 +18908,7 @@ data _null_;
put ' '; put ' ';
put '-- open file and perform the substitution '; put '-- open file and perform the substitution ';
put 'file = io.open(fpath,"r") '; put 'file = io.open(fpath,"r") ';
put 'fcontent = file:read() '; put 'fcontent = file:read("*all") ';
put 'file:close() '; put 'file:close() ';
put 'fcontent = string.gsub( '; put 'fcontent = string.gsub( ';
put ' fcontent, '; put ' fcontent, ';
@@ -18844,7 +18923,7 @@ data _null_;
put 'io.close(file) '; put 'io.close(file) ';
run; run;
%inc "%sysfunc(pathname(work))/ml_gsubfile.lua"; %inc "%sysfunc(pathname(work))/ml_gsubfile.lua" /source2;
%mend ml_gsubfile; %mend ml_gsubfile;
/** /**
@@ -19238,7 +19317,7 @@ data _null_;
put '-- JSON.LUA ENDS HERE '; put '-- JSON.LUA ENDS HERE ';
run; run;
%inc "%sysfunc(pathname(work))/ml_json.lua"; %inc "%sysfunc(pathname(work))/ml_json.lua" /source2;
%mend ml_json; %mend ml_json;
/** /**

View File

@@ -158,7 +158,7 @@
/* send response in SASjs JSON format */ /* send response in SASjs JSON format */
data _null_; data _null_;
file _webout mod lrecl=32000 encoding='utf-8'; file _webout mod lrecl=32000 encoding='utf-8';
length msg $32767 debug $8; length msg $32767 ;
sasdatetime=datetime(); sasdatetime=datetime();
msg=cats(symget('msg'),'\n\nLog Extract:\n',symget('logmsg')); msg=cats(symget('msg'),'\n\nLog Extract:\n',symget('logmsg'));
/* escape the quotes */ /* escape the quotes */
@@ -189,13 +189,16 @@
_PROGRAM=quote(trim(resolve(symget('_PROGRAM')))); _PROGRAM=quote(trim(resolve(symget('_PROGRAM'))));
put ',"_PROGRAM" : ' _PROGRAM ; put ',"_PROGRAM" : ' _PROGRAM ;
put ",""SYSCC"" : ""&syscc"" "; put ",""SYSCC"" : ""&syscc"" ";
put ",""SYSERRORTEXT"" : ""&syserrortext"" "; syserrortext=quote(trim(symget('syserrortext')));
put ",""SYSERRORTEXT"" : " syserrortext;
put ",""SYSHOSTNAME"" : ""&syshostname"" "; put ",""SYSHOSTNAME"" : ""&syshostname"" ";
put ",""SYSJOBID"" : ""&sysjobid"" "; put ",""SYSJOBID"" : ""&sysjobid"" ";
put ",""SYSSCPL"" : ""&sysscpl"" ";
put ",""SYSSITE"" : ""&syssite"" "; put ",""SYSSITE"" : ""&syssite"" ";
sysvlong=quote(trim(symget('sysvlong'))); sysvlong=quote(trim(symget('sysvlong')));
put ',"SYSVLONG" : ' sysvlong; put ',"SYSVLONG" : ' sysvlong;
put ",""SYSWARNINGTEXT"" : ""&syswarningtext"" "; syswarningtext=quote(trim(symget('syswarningtext')));
put ",""SYSWARNINGTEXT"" : " syswarningtext;
put ',"END_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '" '; put ',"END_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '" ';
put "}" @; put "}" @;
if debug ge '"131"' then put '>>weboutEND<<'; if debug ge '"131"' then put '>>weboutEND<<';

View File

@@ -115,6 +115,14 @@
select count(*) into: orig from &lib..&ds; select count(*) into: orig from &lib..&ds;
quit; quit;
%local notfound;
proc sql outobs=10 noprint;
select distinct &col into: notfound separated by ' '
from &lib..&ds
where &col not in (
select &ccol from &clib..&cds
);
%mp_abort(iftrue= (&syscc ne 0) %mp_abort(iftrue= (&syscc ne 0)
,mac=&sysmacroname ,mac=&sysmacroname
,msg=%str(syscc=&syscc after macro query) ,msg=%str(syscc=&syscc after macro query)
@@ -125,7 +133,7 @@
test_description=symget('desc'); test_description=symget('desc');
test_result='FAIL'; test_result='FAIL';
test_comments="&sysmacroname: &lib..&ds..&col has &result values " test_comments="&sysmacroname: &lib..&ds..&col has &result values "
!!"not in &clib..&cds..&ccol "; !!"not in &clib..&cds..&ccol.. First 10 vals:"!!symget('notfound');
%if &test=ANYVAL %then %do; %if &test=ANYVAL %then %do;
if &result < &orig then test_result='PASS'; if &result < &orig then test_result='PASS';
%end; %end;

65
base/mp_getcols.sas Normal file
View File

@@ -0,0 +1,65 @@
/**
@file
@brief Creates a dataset with column metadata.
@details This macro takes the `proc contents` output and "tidies it up" in the
following ways:
@li Blank labels are filled in with column names
@li Formats are reconstructed with default values
@li Types such as DATE / TIME / DATETIME are inferred from the formats
Example usage:
%mp_getcols(sashelp.airline,outds=work.myds)
@param ds The dataset from which to obtain column metadata
@param outds= (work.cols) The output dataset to create. Sample data:
|NAME $|LENGTH 8|VARNUM 8|LABEL $|FORMAT $49|TYPE $1 |DDTYPE $|
|---|---|---|---|---|---|---|
|AIR|8|2|international airline travel (thousands)|8.|N|NUMERIC|
|DATE|8|1|DATE|MONYY.|N|DATE|
|REGION|3|3|REGION|$3.|C|CHARACTER|
<h4> Related Macros </h4>
@li mf_getvarlist.sas
@li mm_getcols.sas
@version 9.2
@author Allan Bowe
**/
%macro mp_getcols(ds, outds=work.cols);
proc contents noprint data=&ds
out=_data_ (keep=name type length label varnum format:);
run;
data &outds(keep=name type length varnum format label ddtype);
set &syslast(rename=(format=format2 type=type2));
name=upcase(name);
if type2=2 then do;
length format $49.;
if format2='' then format=cats('$',length,'.');
else if formatl=0 then format=cats(format2,'.');
else format=cats(format2,formatl,'.');
type='C';
ddtype='CHARACTER';
end;
else do;
if format2='' then format=cats(length,'.');
else if formatl=0 then format=cats(format2,'.');
else if formatd=0 then format=cats(format2,formatl,'.');
else format=cats(format2,formatl,'.',formatd);
type='N';
if format=:'DATETIME' then ddtype='DATETIME';
else if format=:'DATE' or format=:'DDMMYY' or format=:'MMDDYY'
or format=:'YYMMDD' or format=:'E8601DA' or format=:'B8601DA'
or format=:'MONYY'
then ddtype='DATE';
else if format=:'TIME' then ddtype='TIME';
else ddtype='NUMERIC';
end;
if label='' then label=name;
run;
%mend mp_getcols;

View File

@@ -15,7 +15,7 @@
file "&file"; file "&file";
put "&str"; put "&str";
run; run;
%mp_gsubfile(file=&file, pattern=str, replacement=rep) %mp_gsubfile(file=&file, patternvar=str, replacevar=rep)
data _null_; data _null_;
infile "&file"; infile "&file";
input; input;

View File

@@ -14,14 +14,14 @@
We take the standard definition one step further by embedding the informat We take the standard definition one step further by embedding the informat
in the table header row, like so: in the table header row, like so:
|var1:$|var2:best.|var3:date9.| |var1:$32|var2:best.|var3:date9.|
|---|---|---| |---|---|---|
|some text|42|01JAN1960| |some text|42|01JAN1960|
|blah|1|31DEC1999| |blah|1|31DEC1999|
Which resolves to: Which resolves to:
|var1:$|var2:best.|var3:date9.| |var1:$32|var2:best.|var3:date9.|
|---|---|---| |---|---|---|
|some text|42|01JAN1960| |some text|42|01JAN1960|
|blah|1|31DEC1999| |blah|1|31DEC1999|

View File

@@ -22,7 +22,7 @@ for file in files:
for line in infile: for line in infile:
ml.write(" put '" + line.rstrip().replace("'","''") + " ';\n") ml.write(" put '" + line.rstrip().replace("'","''") + " ';\n")
ml.write("run;\n\n") ml.write("run;\n\n")
ml.write("%inc \"%sysfunc(pathname(work))/" + name + ".lua\";\n\n") ml.write("%inc \"%sysfunc(pathname(work))/" + name + ".lua\" /source2;\n\n")
ml.write("%mend " + name + ";\n") ml.write("%mend " + name + ";\n")
ml.close() ml.close()

View File

@@ -10,7 +10,7 @@ end
-- open file and perform the substitution -- open file and perform the substitution
file = io.open(fpath,"r") file = io.open(fpath,"r")
fcontent = file:read() fcontent = file:read("*all")
file:close() file:close()
fcontent = string.gsub( fcontent = string.gsub(
fcontent, fcontent,

View File

@@ -24,7 +24,7 @@ data _null_;
put ' '; put ' ';
put '-- open file and perform the substitution '; put '-- open file and perform the substitution ';
put 'file = io.open(fpath,"r") '; put 'file = io.open(fpath,"r") ';
put 'fcontent = file:read() '; put 'fcontent = file:read("*all") ';
put 'file:close() '; put 'file:close() ';
put 'fcontent = string.gsub( '; put 'fcontent = string.gsub( ';
put ' fcontent, '; put ' fcontent, ';
@@ -39,6 +39,6 @@ data _null_;
put 'io.close(file) '; put 'io.close(file) ';
run; run;
%inc "%sysfunc(pathname(work))/ml_gsubfile.lua"; %inc "%sysfunc(pathname(work))/ml_gsubfile.lua" /source2;
%mend ml_gsubfile; %mend ml_gsubfile;

View File

@@ -389,6 +389,6 @@ data _null_;
put '-- JSON.LUA ENDS HERE '; put '-- JSON.LUA ENDS HERE ';
run; run;
%inc "%sysfunc(pathname(work))/ml_json.lua"; %inc "%sysfunc(pathname(work))/ml_json.lua" /source2;
%mend ml_json; %mend ml_json;

View File

@@ -385,6 +385,7 @@ data _null_;
put ' put ",""SYSERRORTEXT"" : ""&syserrortext"" "; '; put ' put ",""SYSERRORTEXT"" : ""&syserrortext"" "; ';
put ' put ",""SYSHOSTNAME"" : ""&syshostname"" "; '; put ' put ",""SYSHOSTNAME"" : ""&syshostname"" "; ';
put ' put ",""SYSJOBID"" : ""&sysjobid"" "; '; put ' put ",""SYSJOBID"" : ""&sysjobid"" "; ';
put ' put ",""SYSSCPL"" : ""&sysscpl"" "; ';
put ' put ",""SYSSITE"" : ""&syssite"" "; '; put ' put ",""SYSSITE"" : ""&syssite"" "; ';
put ' sysvlong=quote(trim(symget(''sysvlong''))); '; put ' sysvlong=quote(trim(symget(''sysvlong''))); ';
put ' put '',"SYSVLONG" : '' sysvlong; '; put ' put '',"SYSVLONG" : '' sysvlong; ';

View File

@@ -155,6 +155,7 @@
put ",""SYSERRORTEXT"" : ""&syserrortext"" "; put ",""SYSERRORTEXT"" : ""&syserrortext"" ";
put ",""SYSHOSTNAME"" : ""&syshostname"" "; put ",""SYSHOSTNAME"" : ""&syshostname"" ";
put ",""SYSJOBID"" : ""&sysjobid"" "; put ",""SYSJOBID"" : ""&sysjobid"" ";
put ",""SYSSCPL"" : ""&sysscpl"" ";
put ",""SYSSITE"" : ""&syssite"" "; put ",""SYSSITE"" : ""&syssite"" ";
sysvlong=quote(trim(symget('sysvlong'))); sysvlong=quote(trim(symget('sysvlong')));
put ',"SYSVLONG" : ' sysvlong; put ',"SYSVLONG" : ' sysvlong;

View File

@@ -0,0 +1,33 @@
/**
@file
@brief Testing mp_getcols macro
<h4> SAS Macros </h4>
@li mp_getcols.sas
@li mp_assertcolvals.sas
@li mp_assertdsobs.sas
**/
/* valid filter */
%mp_getcols(sashelp.airline,outds=work.info)
%mp_assertdsobs(work.info,
desc=Has 3 records,
test=EQUALS 3,
outds=work.test_results
)
data work.check;
length val $10;
do val='NUMERIC','DATE','CHARACTER';
output;
end;
run;
%mp_assertcolvals(work.info.ddtype,
checkvals=work.check.val,
desc=All values have a match,
test=ALLVALS
)

View File

@@ -30,4 +30,37 @@ run;
iftrue=("&str1"="&str"), iftrue=("&str1"="&str"),
desc=Check that simple replacement was successful, desc=Check that simple replacement was successful,
outds=work.test_results outds=work.test_results
)
/**
* test 2 - replace from additional line
*/
%global str2 strcheck2 strcheck2b;
%let file2=%sysfunc(pathname(work))/file2.txt;
%let pat2=replace/me;
%let str2=with/this;
data _null_;
file "&file2";
put 'line1';output;
put "&pat2";output;
put "&pat2";output;
run;
%mp_gsubfile(file=&file2, patternvar=pat2, replacevar=str2)
data _null_;
infile "&file2";
input;
if _n_=2 then call symputx('strcheck2',_infile_);
if _n_=3 then call symputx('strcheck2b',_infile_);
putlog _infile_;
run;
%mp_assert(
iftrue=("&strcheck2"="&str2"),
desc=Check that multi line replacement was successful (line2),
outds=work.test_results
)
%mp_assert(
iftrue=("&strcheck2b"="&str2"),
desc=Check that multi line replacement was successful (line3),
outds=work.test_results
) )

View File

@@ -590,6 +590,7 @@ data _null_;
put ' put ",""SYSCC"" : ""&syscc"" "; '; put ' put ",""SYSCC"" : ""&syscc"" "; ';
put ' put ",""SYSERRORTEXT"" : ""&syserrortext"" "; '; put ' put ",""SYSERRORTEXT"" : ""&syserrortext"" "; ';
put ' put ",""SYSHOSTNAME"" : ""&syshostname"" "; '; put ' put ",""SYSHOSTNAME"" : ""&syshostname"" "; ';
put ' put ",""SYSSCPL"" : ""&sysscpl"" "; ';
put ' put ",""SYSSITE"" : ""&syssite"" "; '; put ' put ",""SYSSITE"" : ""&syssite"" "; ';
put ' sysvlong=quote(trim(symget(''sysvlong''))); '; put ' sysvlong=quote(trim(symget(''sysvlong''))); ';
put ' put '',"SYSVLONG" : '' sysvlong; '; put ' put '',"SYSVLONG" : '' sysvlong; ';

View File

@@ -215,6 +215,7 @@
put ",""SYSCC"" : ""&syscc"" "; put ",""SYSCC"" : ""&syscc"" ";
put ",""SYSERRORTEXT"" : ""&syserrortext"" "; put ",""SYSERRORTEXT"" : ""&syserrortext"" ";
put ",""SYSHOSTNAME"" : ""&syshostname"" "; put ",""SYSHOSTNAME"" : ""&syshostname"" ";
put ",""SYSSCPL"" : ""&sysscpl"" ";
put ",""SYSSITE"" : ""&syssite"" "; put ",""SYSSITE"" : ""&syssite"" ";
sysvlong=quote(trim(symget('sysvlong'))); sysvlong=quote(trim(symget('sysvlong')));
put ',"SYSVLONG" : ' sysvlong; put ',"SYSVLONG" : ' sysvlong;