Is there a way for me to mimic the use of %if outside of macro in SAS9.4M1?
I know SAS9.4M5 enables to use %if outside of macro, which is really good. Unfortunately, I use SAS9.4M1, but I would like to use this functionality, so I'm looking for a way to bypass it.
Yes. Easily:
data WANT;
set %sysfunc(ifc(&var=1, WORK.TEST1, WORK.TEST2 ));
run;
I'm sorry that I didn't get your point clearly.
I have several lines of codes that I would like to be run only if a certain condition is satisfied. The code may include data steps and some procedures.
Several lines of code that are run depending on if a condition is satisfied in SAS 9.4M1?
You have the perfect tool that works for millions of SAS users when they had SAS 9.4M1. Write a macro with a %IF statement.
Why don't you want to do it that way?
Achieve something similar by creating a macro with the desired %IF
So you had something like:
%if &x=5 %then %do;
data ....
proc ...
%end;
Convert it to:
%macro mymacro;
%if &x=5 %then %do;
data ....
proc ...
%end;
%mend mymacro;
%mymacro;
You could try to get tricky with stuffing the code into a macro variable, or into a file, but it will be much easier to use a macro. Just be careful if the block of code is used to create macro variables. Unless you tell it otherwise any new macro variable created inside a macro is local to the macro and disappears when the macro finishes running.
Upgrade your SAS version, or have it upgraded. The current SAS version is always available for your license.
Or wrap into a macro, as we always did before 9.4M5.
Another application of Maxim 45.
You can do:
%sysfunc(ifc(&var=1,
data WANT;
set WORK.TEST1;
run;
,
data WANT;
set WORK.TEST2;
run;
));
but then you'll probably run into quoting issues, and you're better off using a macro or call execute() as mentioned.
Hi braam,
You can do what you want by using CALL EXECUTE.
Let's say you want to replicate the following:
%let P=PRINT;
%if &P=PRINT %then %do;
proc print data=a;
run;
%end;
You can do this with a data step as follows:
%let P=PRINT;
data _null_;
if "&P"="PRINT" then call execute('proc print data=a; run;');
run;
Please take a look at my blog post CALL EXECUTE made easy for SAS data-driven programming for detailed explanation.
Hope this helps.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.