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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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