BookmarkSubscribeRSS Feed
gfs9311
Calcite | Level 5

We are trying to concantenate column Items based on another column, Shopper_ID. Any suggestions on how we can achieve this?

 

Current result

Shopper_ID        Items                                                

1                         keyboard                                           

1                         mouse                                             

1                         notebook

2                         keyboard                                            

2                         screen protector

3                         case

 

Desired result

Shopper_ID       Items

1                        keyboard, mouse, notebook

2                        keyboard, screen protector

3                        case

3 REPLIES 3
Ksharp
Super User
data have;
input Shopper_ID        Items  $40.;
cards; 
1                         keyboard                                           
1                         mouse                                             
1                         notebook
2                         keyboard                                            
2                         screen protector
3                         case
;
run;
data want;
 length want $ 2000;
 do until(last.Shopper_ID);
  set have;
  by Shopper_ID ;
  want=catx(',',want,items);
 end;
 drop items;
 run;
Reeza
Super User

If you're working with the GUI, then you would first Transpose the data using a TRANSPOSE task and then you can aggregate them using the function CATX in a query and using a calculated column.

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
  • 3 replies
  • 1119 views
  • 0 likes
  • 4 in conversation