Learning SAS? Welcome to the exclusive online community for all SAS learners.

SAS Programming 1 - Use of WHERE and IN commands

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

SAS Programming 1 - Use of WHERE and IN commands

Hi everyone,

 

I'm making my way through SAS Essentials 1 and have stumbled onto a question I can't seem to resolve.  The course offers up some sample code as follows:

 

proc print data=orion.sales;
   where Country='AU';
   where Salary<30000;
run;

 

The program runs, but ignores the where Country='AU'; line.  Based on the instructions in the preceding slides, which suggest enclosing the characters in brackets and with the IN statement, but I still get the same error.  My code:

 

proc print data=orion.sales;
   where Country in ('AU');
   where Salary<30000;
run;

Any suggestions as to what I am missing here?  I also noticed in fiddling with the code, that the 'IN' statement didn't show up on the expected statements list, and references to it seem a bit few and far between online.  Is there a better way of doing this sort of thing?

 

Thanks for your suggestions!


Accepted Solutions
Solution
‎12-30-2015 02:38 PM
Super User
Posts: 5,083

Re: SAS Programming 1 - Use of WHERE and IN commands

When multiple WHERE statements appear within the same step, the later WHERE statement replaces the earlier one.  That's why you won't see the first one in the log.  

 

To get both WHERE conditions applying, use a single WHERE statement:

 

where country='AU' and salary < 30000;

 

I believe that this might work as well, but you'll have to try it and see:

 

where country='AU';

where _same_ and salary < 30000;

 

Good luck.

View solution in original post


All Replies
Solution
‎12-30-2015 02:38 PM
Super User
Posts: 5,083

Re: SAS Programming 1 - Use of WHERE and IN commands

When multiple WHERE statements appear within the same step, the later WHERE statement replaces the earlier one.  That's why you won't see the first one in the log.  

 

To get both WHERE conditions applying, use a single WHERE statement:

 

where country='AU' and salary < 30000;

 

I believe that this might work as well, but you'll have to try it and see:

 

where country='AU';

where _same_ and salary < 30000;

 

Good luck.

Occasional Contributor
Posts: 9

Re: SAS Programming 1 - Use of WHERE and IN commands

Yes, that did the trick. Precisely the problem I had, and the fix I ended up uncovering. Thank you very much!
Occasional Contributor
Posts: 9

Re: SAS Programming 1 - Use of WHERE and IN commands

Figured it out. No sooner did I post than I read that SAS will only handle one where statement at a time. Reworked to include AND, and now the program runs fine. More questions to follow, I am sure!
☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 421 views
  • 2 likes
  • 2 in conversation