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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.