DATA Step, Macro, Functions and more

proc sql- where clause not working

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

proc sql- where clause not working

proc sql;
create table numsn as
select distinct b.table,b.column,b.origin,b.originwhere,b.algorithm,b.origindescription,b.role,b.term,b.MAPSUBMITTED
from vcol a right join source_columns b
on a.origin=b.origin
where b.term like "(%)" or b.term="*" and b.MAPSUBMITTED="Y"
group by b.table,b.column,b.origin,b.originwhere,b.algorithm
order by b.table,b.column,b.origin,b.originwhere,b.algorithm;
quit;

 

But in the above code my b.MAPSUBMITTED="Y" condition is not working as i get valiues which are not Y also. any clue where i am wrong ?


Accepted Solutions
Solution
‎04-03-2017 03:42 AM
Super User
Posts: 3,101

Re: proc sql- where clause not working

You need brackets to ensure the AND works separately from the OR:

 

where (b.term like "(%)" or b.term="*") and b.MAPSUBMITTED="Y"

View solution in original post


All Replies
Solution
‎04-03-2017 03:42 AM
Super User
Posts: 3,101

Re: proc sql- where clause not working

You need brackets to ensure the AND works separately from the OR:

 

where (b.term like "(%)" or b.term="*") and b.MAPSUBMITTED="Y"
Super User
Posts: 6,928

Re: proc sql- where clause not working

"and" is evaluated before "or", so the first condition for b.term like "(%)" takes precedence. You may have to enclose the "or" in brackets:

where (b.term like "(%)" or b.term="*") and b.MAPSUBMITTED="Y"

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 164 views
  • 1 like
  • 3 in conversation