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 |
data want;
set have;
by idno visitdate;
if last.visitdate;
run;
data want;
set have;
by idno visitdate;
if last.visitdate;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.