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

Hi All,

 

I need to recode a set of 8 variables into a single variable, such that if all 8 are missing then the new variable is missing, but if even one of the variable = '1' then the new variable = '1'; else the new variable = '0'. I know how to that in long hand (see below), but was wondering is there was a better way to do this.

 

data two; set one;

if var1 = . and var2 = . and var3 = . and var4 = . and var5 = . and var6 = . and var7 = . and var8 = . then new_var = .;

else if var1 = 1 or var2 = 1 or var3 = 1 or var4 = 1 or var5 = 1 or var6 = 1 or var7 = 1 or var8 = 1 then new_var = 1;

else new_var = 0;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

As long as you know the values are 0/1 then just take the max.

new_var=max(of var1-var8);

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

As long as you know the values are 0/1 then just take the max.

new_var=max(of var1-var8);

 

aowais
Obsidian | Level 7

Thanks! It works!

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
  • 2 replies
  • 1420 views
  • 0 likes
  • 2 in conversation