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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: