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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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