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;
As long as you know the values are 0/1 then just take the max.
new_var=max(of var1-var8);
As long as you know the values are 0/1 then just take the max.
new_var=max(of var1-var8);
Thanks! It works!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.