Senior User
Posts: 1

# Multiple Variables into one variable

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!

Super User
Posts: 23,354

## Re: Multiple Variables into one variable

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!

PROC Star
Posts: 1,604

## Re: Multiple Variables into one variable

``````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;``````
Super User
Posts: 6,644

## Re: Multiple Variables into one variable

Is it impossible for a person to have two conditions?

Discussion stats
• 3 replies
• 126 views
• 1 like
• 4 in conversation