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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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