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!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.