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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.