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.
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;
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.
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;
Thank you for your resposes. 🙂
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.