BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aowais
Obsidian | Level 7

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
if coalesce(var1,var2)>. then new_var=var1=var2=1;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20
if coalesce(var1,var2)>. then new_var=var1=var2=1;
aowais
Obsidian | Level 7

Thank you. This works.

Reeza
Super User
Do you understand the calculations happening there? You may want to look into IFN() as well, especially for dealing with a single variable, which has a fourth(or 5th) parameter to deal with MISSING.
aowais
Obsidian | Level 7

I tried that, but it didn't work.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1238 views
  • 0 likes
  • 3 in conversation