Hello,
I'm trying to create a variable from two others which should be missing if both are missing, '1' if both are '1' and '0' otherwise. I know how to do this in longhand (see below), but is there a shorter way?
data two; set one;
if var1 = . and var2 = . then new_var = .;
else if var1 = 1 and var2 = 1 then new_var = 1;
else new_var = 0;
run;
if coalesce(var1,var2)>. then new_var=var1=var2=1;
if coalesce(var1,var2)>. then new_var=var1=var2=1;
Thank you. This works.
I tried that, but it didn't work.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.