SAS Programming

DATA Step, Macro, Functions and more
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).

sas-innovate-white.png

Join us for our biggest event of the year!

Four days of inspiring keynotes, product reveals, hands-on learning opportunities, deep-dive demos, and peer-led breakouts. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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