DATA Step, Macro, Functions and more

base sas

Accepted Solution Solved
Reply
Contributor
Posts: 63
Accepted Solution

base sas

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

 

 

 


Accepted Solutions
Solution
‎03-13-2017 03:45 AM
Super User
Posts: 5,071

Re: base sas

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


All Replies
Solution
‎03-13-2017 03:45 AM
Super User
Posts: 5,071

Re: base sas

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 148 views
  • 1 like
  • 2 in conversation