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

I have a dataset of patient records with multiple rows per visit date and multiple visit dates.  I used first. to create a cumulative sum of costs across the rows for a single date and a record counter.  Now I want to drop all rows except the one with my cumulative sum (the highest counter) for each patient and visit date.  

Example data:

idno visitdate pay cumupay counter
1 5/5/2019 5 5 1
1 5/5/2019 5 10 2
1 10/31/2019 5 5 1
1 12/25/2019 5 5 1
1 12/25/2019 5 10 2
1 12/25/2019 5 15 3
2 7/4/2019 7 7 1
2 7/4/2019 7 14 2
3 9/2/2019 9 9 1

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data want;
 set have;
 by idno visitdate;
 if last.visitdate;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data want;
 set have;
 by idno visitdate;
 if last.visitdate;
run;
ash
Fluorite | Level 6 ash
Fluorite | Level 6
Thank you. That's probably the only combo I hadn't tried, since I thought that would have kept only the last visitdate (from my example, I would think that would have kept: ID = 1 and only the last row of the last visitdate (12/25/2019).

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 900 views
  • 1 like
  • 2 in conversation