BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ccaudillo100
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ccaudillo100
Obsidian | Level 7

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;

 

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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;
ccaudillo100
Obsidian | Level 7

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;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 713 views
  • 1 like
  • 2 in conversation