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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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