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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.