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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1350 views
  • 1 like
  • 2 in conversation