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?
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?
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.
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 */
this is the log that I got.
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?
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.
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.
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.