Help using Base SAS procedures

Deleting groups of observations.

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

Deleting groups of observations.

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


Accepted Solutions
Solution
‎08-14-2017 03:25 PM
Super User
Posts: 23,776

Re: Deleting groups of observations.

[ Edited ]
Posted in reply to andrewfau

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


All Replies
Trusted Advisor
Posts: 1,837

Re: Deleting groups of observations.

[ Edited ]
Posted in reply to andrewfau

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 */

Contributor
Posts: 32

Re: Deleting groups of observations.

log.jpg

this is the log that I got. 

Solution
‎08-14-2017 03:25 PM
Super User
Posts: 23,776

Re: Deleting groups of observations.

[ Edited ]
Posted in reply to andrewfau

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. 

 

 

☑ This topic is solved.

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

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