DATA Step, Macro, Functions and more

can I plug in %include statement inside the data step?

Reply
Frequent Contributor
Posts: 133

can I plug in %include statement inside the data step?

is this legal?

proc print data=sashelp.cars;

%include 'c:\data\var1.sas';

run;

I tested it, it returns the result, but I don't know if it the right way to do?

Respected Advisor
Posts: 4,930

Re: can I plug in %include statement inside the data step?

Yes, the only restriction is that you include complete statements, not partial statements. You cannot do

data _null_;

set have;

if x > 0 then %include 'myFile.sas";

run;

That doesn't work. But you can do:

data _null_;

set have;

if x>0 then do;

%include "myFile.sas";

end;

run;

But you must remember that the inclusion will occur even if x <= 0. The do block will not be executed, but the code from myFile.sas will be included.

Hope that helps.

PG

PG
Ask a Question
Discussion stats
  • 1 reply
  • 174 views
  • 0 likes
  • 2 in conversation