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

Hi I need help in extracting last claim date and corresponding claim amount

 

data HAVE;

input policy_no$ dt;

input amount$;

informat dt datetime.;

format dt datetime.;

cards;

1     500        21MAY2018

1     3000     22DEC2018

2     800      01JAN2019

3     550      21MAY2017

3     130      05JUN2020

run;

 

 

DATA WANT

policy_no    amount         date

1                 3000        22DEC2018

2                 800          01JAN2019

3                130           05JUN2020

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Please test your data step code before posting, so we do not have to fix it.

 

See this:

data HAVE;
input policy_no $ amount dt :date9.;
format dt date9.;
cards;
1     500        21MAY2018
1     3000     22DEC2018
2     800      01JAN2019
3     550      21MAY2017
3     130      05JUN2020
;

data want;
set have;
by policy_no dt; /* dt included here to force correct sort order */
if last.policy_no;
run;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Please test your data step code before posting, so we do not have to fix it.

 

See this:

data HAVE;
input policy_no $ amount dt :date9.;
format dt date9.;
cards;
1     500        21MAY2018
1     3000     22DEC2018
2     800      01JAN2019
3     550      21MAY2017
3     130      05JUN2020
;

data want;
set have;
by policy_no dt; /* dt included here to force correct sort order */
if last.policy_no;
run;
RichardDeVen
Barite | Level 11

Just to clarify for beginners

by policy_no dt; /* dt included here to force correct sort order */

The DT in the BY statement does not force or implicitly sort the data.  The DT ensures proper operation of the algorithm (i.e. business rule) because the DATA Step will ERROR: if the data are not in the expected sorted order.  A more precise comment might be  /* dt included here to assert correct sort order */

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 894 views
  • 2 likes
  • 3 in conversation