Wednesday, December 18, 2013

SAS: Conditional %include

I have a SAS program which is generating SAS programs, and I want to conditionally use %include; that is, if the %include file exists, then %include it.  This code demonstrates how.

* SAS conditional %include ;
* See also http://www.sascommunity.org/wiki/Conditionally_Executing_Global_Statements ;

data _null_;
file "c:\temp\a.txt";
put "a = 1;";
run;

data _null_;
file "c:\temp\b.txt";
put "b = 1;";
run;

%let include_file=c:\temp\a.txt;
%let include_file=c:\temp\c.txt;
%let include_file=c:\temp\b.txt;

data Work.test;
%sysfunc(ifc(%sysfunc(fileexist("&include_file")),
    %include "&include_file";, %put File "&include_file" not found.;));
run;

proc print data=Work.test;
run;


No comments:

Post a Comment