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

I have a data set with a variable that specifies a use code from 000-099. I only want to keep observations that have the codes 000, 001, 002, 004, or 005. Everything I am reading is telling me I can use a statement like this:

 

if dor_uc = ('000' '001' '002' '004' '005');

else delete;

 

My log is telling me that is an incomplete if-then statement, which I get because there is no 'then' statement following the condition. In examples I am finding, though, that statement keeps the observations with the specified criteria without a 'then' statement following the condition. 

 

Is there a better if-then statement to write to only include observations that fit multiple criteria?

 

 

dor_uc.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Your IF doesn't have a THEN so you can't have an ELSE is what it's saying. 

 

Why not reverse the logic for a single line of code, use NOT IN?

 

delete if then.JPG

 

 PS. Don't post images, post your code and log directly into the forum please. Otherwise it means we have to type out your code instead of copy/paste and fix. 

 

 

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

Just change the equal sign into  IN :

 

if dor_uc in ('000' '001' '002' '004' '005') then;

else delete;   /* else need preceding then */

 

OR:

if dor_uc in ('000' '001' '002' '004' '005');  /* subsets only desired values */

andrewfau
Fluorite | Level 6

log.jpg

this is the log that I got. 

Reeza
Super User

Your IF doesn't have a THEN so you can't have an ELSE is what it's saying. 

 

Why not reverse the logic for a single line of code, use NOT IN?

 

delete if then.JPG

 

 PS. Don't post images, post your code and log directly into the forum please. Otherwise it means we have to type out your code instead of copy/paste and fix. 

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 889 views
  • 2 likes
  • 3 in conversation