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

Hello Experts - I have the following have dataset and I need the want data set.

 

Data have;

input claim_id $ visit;

datalines;

A0001 1

A0001 2

A0001 3

B0001 5

B0001 3

;

run;

 

what I need is:

 

Want:

Claim_id   Visit

A0001       1,2,3

B0001       5,3

 

 Any help is appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Alternative solution:

 

Proc sort data=have; by claim_id visit; run; /* assuming data is not sorted already */

data want;
 set have(rename=(visit=visit1));
  by claim_id;
       length visit $10;  /* adapt length to max number of visits */
       retain visit;
       if first.claim_id then visit=' ';
       visit = catx(',' , visit, visit1);
       if last.claim_id then output;
run;

View solution in original post

3 REPLIES 3
kiranv_
Rhodochrosite | Level 12

data want;
length claim_id $5. cat $20.;
do until (last.claim_id);
set have;
by claim_id notsorted;
cat=catx(',',cat,visit);
end;
drop visit;
run;
proc print;run;

 

My answer as is copy of @Haikuo previous answer shown below.

https://communities.sas.com/t5/Base-SAS-Programming/Concatenate-multiple-rows-into-a-single-value/td...

Shmuel
Garnet | Level 18

Alternative solution:

 

Proc sort data=have; by claim_id visit; run; /* assuming data is not sorted already */

data want;
 set have(rename=(visit=visit1));
  by claim_id;
       length visit $10;  /* adapt length to max number of visits */
       retain visit;
       if first.claim_id then visit=' ';
       visit = catx(',' , visit, visit1);
       if last.claim_id then output;
run;
PBsas
Obsidian | Level 7

Thank you for your resposes. 🙂

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
  • 3 replies
  • 1807 views
  • 2 likes
  • 3 in conversation