🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-26-2020 12:39 PM
(755 views)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
set have;
by idno visitdate;
if last.visitdate;
run;
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
set have;
by idno visitdate;
if last.visitdate;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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).