BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sassypixie
Fluorite | Level 6

I want to create a where statement where the variable is equal to 1,3 , or 4 but I am having trouble getting the output I want. I've tried a few methods but I'll just post the last one I tried. Basically I am trying to get the where statement to exclude 2 and only include 1, 3 and 4. Any suggestions? Thank you

 

Proc means data=data;
var chol;
class sex;
where (2>race>2);
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

And "where" (put intended) did you learn the expression

    

where (2>race>2);

 SAS will interpret this to mean the RACE is BOTH greater than 2 and less than 2.  In other words, it insert an "and" not an "or".  (Thus expressions like  1<race<3 function as actual subseting filters.

 

try:

where (race ^= 2);

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

3 REPLIES 3
mkeintz
PROC Star

And "where" (put intended) did you learn the expression

    

where (2>race>2);

 SAS will interpret this to mean the RACE is BOTH greater than 2 and less than 2.  In other words, it insert an "and" not an "or".  (Thus expressions like  1<race<3 function as actual subseting filters.

 

try:

where (race ^= 2);

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
sassypixie
Fluorite | Level 6

Thank you very much!

ballardw
Super User

Alternate

 

Where race in (1 3 4);

if you know an explicit list of values that you want to keep. Some times the list to keep is shorter than a list to exclude so it is good to know multiple ways to filter values.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1238 views
  • 0 likes
  • 3 in conversation