Help using Base SAS procedures

Or statement for sql in a macro

Accepted Solution Solved
Reply
Regular Contributor
Posts: 194
Accepted Solution

Or statement for sql in a macro

 %if &table=3 or &table=3a or &table=3b or &table=3c %then %do; 
    proc sql;
	create table want1 as
    select a.county, c.count, c.imm, c.missing, c.med, c.bel, c.oth, c.over
     from counties as a
	left join have as c
		on a.county=c.county;
   quit;
 %end;

I inherited a program am trying to modify it.

 

table 'have' has a list of 50 counties along with additional variables.

table 'counties' has a list of all desired 60 counties, one per rown

table 'want' I need all 60 counties listed, one per row, in the table 'counties' joined by county name to the table 'have' with the following column names:

 

county  count imm missing med bel oth over

 

 

 

 

When I run the sql code without using the or statement (i,e, repeat  , the sql statement works (I get 60 rows). If I run the macro just with one table name, I still am getting only 50 rows as output.  How do I troubleshoot? Thanks.


Accepted Solutions
Solution
‎07-04-2017 05:35 PM
Super User
Posts: 7,762

Re: Or statement for sql in a macro

If you get different outcomes from this step, then it is not the %if condition, but changes in the input datasets. There is nothing dynamic in the SQL, so it will always work the same, but the outcome will depend on the input datasets.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 19,770

Re: Or statement for sql in a macro

From what you've shown, your code will only ever run once, there's nothing dynamic in it, so the results will be the same regardless of the table name(s) as long as they meet one of the table names in the OR list.

Are you expecting it to run multiple times?

Solution
‎07-04-2017 05:35 PM
Super User
Posts: 7,762

Re: Or statement for sql in a macro

If you get different outcomes from this step, then it is not the %if condition, but changes in the input datasets. There is nothing dynamic in the SQL, so it will always work the same, but the outcome will depend on the input datasets.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Regular Contributor
Posts: 194

Re: Or statement for sql in a macro

Posted in reply to KurtBremser

Thanks everyone. I figured out what I did wrong.

Super User
Posts: 19,770

Re: Or statement for sql in a macro

@jcis7 please mark one of the solutions as correct.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 161 views
  • 0 likes
  • 3 in conversation