BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10
%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.

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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.

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

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.

ballardw
Super User

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;

SAS_inquisitive
Lapis Lazuli | Level 10

@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? 

FreelanceReinh
Jade | Level 19

@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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1146 views
  • 2 likes
  • 3 in conversation