Hi Everyone,
My data is as below, each group_id has multiple row.
I want to join the text within each group_id.
For group_id=1, it has 3 rows with var =x, yy, zzz.
The output should have 2 columns
group_id | join_text
1 | x, yy, zzz
2 | aaa, b
3 | c
Can you please help me to get it?
Thank you so much.
HHCFX
data have;
input group_id var1 $;
datalines;
1 x
1 yy
1 zzz
2 aaa
2 b
3 c
;run;
data want;
set have;
by group_id; /* assuming dataset is sorted by group_ID */
length join_text $100; /* adapt length to max expected */
retain join_text;
if first.group_ID then join_text = var1;
else join_text = catx(',',join_text,var1);
if last.group_id then output;
drop var1;
run;
data want;
set have;
by group_id; /* assuming dataset is sorted by group_ID */
length join_text $100; /* adapt length to max expected */
retain join_text;
if first.group_ID then join_text = var1;
else join_text = catx(',',join_text,var1);
if last.group_id then output;
drop var1;
run;
Thank you, Shmuel!
HHCFX
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.