%macro m(text); proc sql noprint; create table t as select * from sashelp.class %if &text ^=%str() %then where name="William"; %str(;) quit; %mend m; %m(tx)
I have a SAS program above. When I remove %str( ; ), it does not work.
Hello @SAS_inquisitive,
I think you can simplify the line "%if ..." to
%if &text ^= %then where name="William";;
The first semicolon ends the %THEN statement, the second semicolon ends the SELECT statement.
Hello @SAS_inquisitive,
I think you can simplify the line "%if ..." to
%if &text ^= %then where name="William";;
The first semicolon ends the %THEN statement, the second semicolon ends the SELECT statement.
You should specify "how it doesn't work".
If you run the not working code with Options mprint;
I think you will see that there is no semi-colon in the code before the Quit. So Quit is encountered in an expected place:
...
from sashelp.class
quit;
or
...
from sashelp.class
where name="William"
quit;
@FreelanceReinhand @ballardw. Thank you. I also wonder the progam flow of this code. Does the %IF statment executes first to generate the SAS statements before Proc Sql statement?
@SAS_inquisitive wrote:
Does the %IF statment executes first to generate the SAS statements before Proc Sql statement?
Yes, sure. That's how SAS macro language works. Roughly speaking, the macro processor generates the code (data steps, proc steps, other non-macro statements) that is eventually sent to the compiler. Please see the documentation How SAS Processes Statements with Macro Activity for a detailed overview.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.