BookmarkSubscribeRSS Feed
Nasya
Obsidian | Level 7

Hi,

 

I need help in concatenation.

I have two variables : ID Agent and Agentoth (all CHAR)

Sample data:              01 Steriods     ABC

                                   02 Other          XYZ

                                   03 ATG

Expected out put is : Agent,agentoth

 

data med;
     by ID;
     attrib AGENT_ length=$100;

if index(lowcase(AGENT),"other")>0 then do;
		AGENT_= "Other, "|| AGENTOTH; 
 	end;
 	if AGENT_ =" " then AGENT_ = AGENT;

	output step_01_dat_final;
run;

This code above concatenates only if the agent name is 'Other'. I need to concatenate if there is anything in the Agenoth, else leave.

Any suggestions?

Thank you,

 

Regards,

Nasya

 

1 REPLY 1
Reeza
Super User

I believe the CAT_ family of functions do that automatically, so you don't need to account for that.

 

data have;
infile cards truncover;
input id $ agent $ agentoth $;
cards;
1 Fred Flinstone
2 Angela
3 Barney Rubble
;;
run;

data want;
set have;

var = catx(', ', agent, agentoth);
run;

@Nasya wrote:

Hi,

 

I need help in concatenation.

I have two variables : ID Agent and Agentoth (all CHAR)

Sample data:              01 Steriods     ABC

                                   02 Other          XYZ

                                   03 ATG

Expected out put is : Agent,agentoth

 

data med;
     by ID;
     attrib AGENT_ length=$100;

if index(lowcase(AGENT),"other")>0 then do;
		AGENT_= "Other, "|| AGENTOTH; 
 	end;
 	if AGENT_ =" " then AGENT_ = AGENT;

	output step_01_dat_final;
run;

This code above concatenates only if the agent name is 'Other'. I need to concatenate if there is anything in the Agenoth, else leave.

Any suggestions?

Thank you,

 

Regards,

Nasya

 


 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 574 views
  • 0 likes
  • 2 in conversation