Does anyone know if there's an efficient way to create a single variable from multiple variables. For example, person was asked if they've ever had a condition, then asked to specify the condition. When the data was entered, each condition was listed as its own binary (yes/no) variable without standardizing the variable names.
Condition X Y Z
1 1 0 0
1 0 0 1
0 0 0 0
1 0 1 0
I want it to look like this:
Condition Condition_type
1 X
1 Z
0
1 Y
Thanks!
Use WHICHN to find the value of the one with the 1 and then VNAME to get the name of the variable:
array myVars(*) x y z;
index = whichn(1, of myVars(*));
if index ne 0 then VarName = vname(myvars(index));
@rotana wrote:
Does anyone know if there's an efficient way to create a single variable from multiple variables. For example, person was asked if they've ever had a condition, then asked to specify the condition. When the data was entered, each condition was listed as its own binary (yes/no) variable without standardizing the variable names.
Condition X Y Z
1 1 0 0
1 0 0 1
0 0 0 0
1 0 1 0
I want it to look like this:
Condition Condition_type
1 X
1 Z
0
1 Y
Thanks!
data have;
input Condition X Y Z;
cards;
1 1 0 0
1 0 0 1
0 0 0 0
1 0 1 0
;
data want;
set have;
array t(*) x--z;
temp=whichn(1, of t[*]);
if temp then condition_type=vname(t(temp));
drop temp;
run;
Is it impossible for a person to have two conditions?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.