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

Hi, I am looking for a way to combine 2 records in a single dataset.
These 2 records have duplicate IDs but i can't figure out how to make them into a single row.
Untitled.png
I am hoping to make them into something like this;

         POLICYID                              RIDER_LISTS
   1    I100786-4599318572             RTWMR4,RTWWP1,RTWMR2,RTWHB1

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Here is an example

 

data have;
input id $ list $;
datalines;
123 ab,cd
123 ef,ghj
012 abcd
;

data want;
length newList $200; /* Make new list large enough to hold the longer lists */
retain newList;
set have;
by id notsorted;
if first.id then newList = list;
else newList = catx(",", newList, list);
if last.id then output;
rename newList=list;
drop list;
run;
PG

View solution in original post

3 REPLIES 3
mkeintz
PROC Star

By what rule do you know they are from the same id?

 

Does the number of records per policy vary?   Or is it always 2?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Wken1122
Obsidian | Level 7

From the excel tables. But unsure why it became null..

PGStats
Opal | Level 21

Here is an example

 

data have;
input id $ list $;
datalines;
123 ab,cd
123 ef,ghj
012 abcd
;

data want;
length newList $200; /* Make new list large enough to hold the longer lists */
retain newList;
set have;
by id notsorted;
if first.id then newList = list;
else newList = catx(",", newList, list);
if last.id then output;
rename newList=list;
drop list;
run;
PG

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 997 views
  • 0 likes
  • 3 in conversation