BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
raja777pharma
Fluorite | Level 6

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_01C_02C_03C_04C_05C_06C_07New_Var
10001        
10002  x    C_03_X
10003     x C_06_X
10004   x  xMultiple
10005 x     C_02_X
10006        
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20
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;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 342 views
  • 5 likes
  • 2 in conversation