BookmarkSubscribeRSS Feed
Valentin_HU
Calcite | Level 5
Hi there,
I'm not sure if this is the right place for this post, if not I'm sorry!
I have the following problem:
My data looks like that (simplified):
Text group
text1 1
text2 1
text3 1
text4 1
text1 2
text2 2
text1 3
text2 3
text3 3

Now I want to concatenate the strings in 'Text' for each group so that the data looks like that:

Text group
text1_text2_text3_text4 1
text1_text2 2
text1_text2_text3 3

Can anyone help me with this? Another question here is the maximal length of a string variable.

Thanks!

Valentin
1 REPLY 1
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Vvalentin_HU,

This is a solution:
[pre]
data i;
input Text $ group;
datalines;
text1 1
text2 1
text3 1
text4 1
text1 2
text2 2
text1 3
text2 3
text3 3
run;
data r;
retain t;
length t $100;
set i;
if First.group then t="";
t=CATX('_',t,text);
if Last.group then output;
by group;
keep t group;
run;
[/pre]
Sincerely,
SPR

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