Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to execute %include conditionally in data step

Status
Not open for further replies.

6656

Programmer
Nov 5, 2002
104
US
Hi all,

How to conditionally submit a SAS program (i.e saspgm.sas) with %include in data step without %macro statement and
%if.. %then..?

In below sample, the saspgm.sas will be submitted regardless what the condition is. How to make it only run when &x=1:

%let x=0;
data _null_;
if &x=1 then do;
%inc 'c:\saspgm.sas';
more .....
end;
else do;
put 'saspgm.sas not be submitted.';
end;
run;

Thanks in advance.

Mike
 
Mike,
Could you explain the need for this in your code. If you are doing data-step level operations why the need for another SAS process? If you are doing datastep level process and you need to insert some code (meaning the inserted text will execute on that datastep) you need the macro engine anyway.

In short if you want to include another sas (text) file use the %macroname call. What I do is make the inserted text file a macro. For example,'test.sas' is needed on a conditional basis. Have the 'test.sas' text file begin with the line %macro my_name; and end with the %mend statement. Then you could conditionally call that file. I have two ways right now.

Ex.
%macro myfile;
%inc "your_file_name.sas";
%mend myfile;

%let x=0;

data name;
Your_logic_here;.....
if &x=1 then do;
%myfile;
end;
else....
run;

Now this works for running datastep procesees, meaning your included code will run at that datastep level.

I hope that I have given you some ideas.

Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top