Hello,
I am wanting to take a table in SAS to go from looking like this:
Group_Num | Name (Char) |
1 | bob |
1 | sally |
1 | chris |
1 | molly |
1 | sam |
2 | bobby |
2 | beth |
2 | collin |
2 | sam |
To looking like this
Group_Num | Name |
1 | bob, sally, chris, molly, sam |
2 | bobby, beth, collin, sam |
Any advice on how to do this? I know concat is for when you do this to columns in one row. But I was unsure of how else to refer to this. Thanks in advanced for any help.
This ended up sending it into repeating the same combination of lines over and over again for each Group_Num. I found this code that was able to run it correctly. From: https://communities.sas.com/t5/SAS-Enterprise-Guide/Concatenating-a-column-based-on-another-column/t...
data want;
length want $ 2000;
do until(last.Shopper_ID);
set have;
by Shopper_ID ;
want=catx(',',want,items);
end;
drop items;
run;
Try this
data have;
input Group_Num Name $;
datalines;
1 bob
1 sally
1 chris
1 molly
1 sam
2 bobby
2 beth
2 collin
2 sam
;
data want;
set have(rename = name = n);
by Group_Num;
length name $200;
name = catx(', ', name, n);
if last.Group_Num;
retain name;
drop n;
run;
This ended up sending it into repeating the same combination of lines over and over again for each Group_Num. I found this code that was able to run it correctly. From: https://communities.sas.com/t5/SAS-Enterprise-Guide/Concatenating-a-column-based-on-another-column/t...
data want;
length want $ 2000;
do until(last.Shopper_ID);
set have;
by Shopper_ID ;
want=catx(',',want,items);
end;
drop items;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.