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

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2293 views
  • 0 likes
  • 3 in conversation