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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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