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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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