%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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.