BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
molla
Fluorite | Level 6

Hii

 

I have the following data set

 

subid   names

001       ruby

001       ricky

001       subbu

002       kee

002       chai

003       deep

004       suri

 

I need output as

subid    names

001       ruby,ricky,subbu

002       kee,chai

003       deep

004       suri

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Here's a straightforward approach:

 

data want;

set have;

by subid;

length all_names $ 200;

if first.subid then all_names = names;

else all_names = catx(',' , all_names, names);

if last.subid;

retain all_names;

run;

 

The only thing I would warn you about is to consider whether this is really a good step to take.  If you merely want to print the data in this new form then go right ahead.  But if you are analyzing or summarizing the data for some other purpose, SAS has many tools that let you process multiple observations per SUBID.  It may not be necessary to change the form of the data.

View solution in original post

1 REPLY 1
Astounding
PROC Star

Here's a straightforward approach:

 

data want;

set have;

by subid;

length all_names $ 200;

if first.subid then all_names = names;

else all_names = catx(',' , all_names, names);

if last.subid;

retain all_names;

run;

 

The only thing I would warn you about is to consider whether this is really a good step to take.  If you merely want to print the data in this new form then go right ahead.  But if you are analyzing or summarizing the data for some other purpose, SAS has many tools that let you process multiple observations per SUBID.  It may not be necessary to change the form of the data.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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