Hello Please help to get NEW_VAR based on C_01 to C_07 var values
if Only C_03 value as 'x' then NEW_VAR value will be the variable name and value
if more than value 'x' in C_01 to C_07 then New_var value will be 'Multiple'
can we code this in array or any simple code ?
SUBJID | C_01 | C_02 | C_03 | C_04 | C_05 | C_06 | C_07 | New_Var |
10001 | ||||||||
10002 | x | C_03_X | ||||||
10003 | x | C_06_X | ||||||
10004 | x | x | Multiple | |||||
10005 | x | C_02_X | ||||||
10006 |
data have;
infile cards truncover;
input SUBJID (C_01 C_02 C_03 C_04 C_05 C_06 C_07) ($);
cards;
10001 . . . . . . .
10002 . . x . . . .
10003 . . . . . x .
10004 . . . x . . x
10005 . x . . . . .
10006 . . . . . . .
;
data want;
set have;
array t c_01-c_07;
length New_Var $32;
_n_=dim(t)-cmiss(of t(*));
if _n_>1 then New_Var='Multiple';
else if _n_=1 then New_Var=catx(' ',vname(t(whichc('x',of t(*)))),'X');
run;
data have;
infile cards truncover;
input SUBJID (C_01 C_02 C_03 C_04 C_05 C_06 C_07) ($);
cards;
10001 . . . . . . .
10002 . . x . . . .
10003 . . . . . x .
10004 . . . x . . x
10005 . x . . . . .
10006 . . . . . . .
;
data want;
set have;
array t c_01-c_07;
length New_Var $32;
_n_=dim(t)-cmiss(of t(*));
if _n_>1 then New_Var='Multiple';
else if _n_=1 then New_Var=catx(' ',vname(t(whichc('x',of t(*)))),'X');
run;
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.