BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
claimid date rownumber
111 1/31/2010 1
111 2/28/2010 2
111 3/31/2010 3

112 1/31/2010 2
112 3/31/2010 1




how to get values like follows:
111 3/31/2010 3
112 3/31/2010 1


the req is to get the claimid for those dates which are latest and its rownumber
8 REPLIES 8
ArtC
Rhodochrosite | Level 12
Assuming that your table is not too very large, one way:

[pre]
data claims;
input claimid date mmddyy10. rownumber;
format date date9.;
datalines;
111 01/31/2010 1
111 02/28/2010 2
111 03/31/2010 3
112 1/31/2010 2
112 3/31/2010 1
;
run;
proc sort data=claims;
by claimid descending date;
run;

data latestclaims;
set claims;
by claimid;
if first.claimid;
run;
proc print data=latestclaims;
run;
[/pre]
SASPhile
Quartz | Level 8
ArtC,
How to get this in proc Sql?

Claimid for the latest date and its max row number?
ArtC
Rhodochrosite | Level 12
Try something like:

[pre]
proc sql;
select claimid, date, rownumber
from claims
group by claimid
having date=max(date)
;
quit;
[/pre]
data_null__
Jade | Level 19
You may want to consider PROC SUMMARY's IDGROUP OUTPUT statement option.

[pre]
proc summary data=claims nway;
class claimid;
output out=claim2(drop=_:) idgroup(max(date) out(date rownumber)=);
run;
[/pre]
Doc_Duke
Rhodochrosite | Level 12
SUMMARY requires sorting the data. The most efficient approach my be data volume dependent.
ArtC
Rhodochrosite | Level 12
I really like Data_NULL_'s SUMMARY solution. It has the added advantage of allowing the top n values through the IDGROUP. Since the CLASS statement is being used the result is sorted on CLAIMID, but the incoming data need not be sorted.
Doc_Duke
Rhodochrosite | Level 12
I missed the CLASS statement. SASPhile will just have to experiment. He often has large datasets, so a CLASS could either run out of memory and abort or use virtual memory and take a long time.
data_null__
Jade | Level 19
The CLASS statement may have trouble when the data have very high cardinality. I don’t know just how big that number is.

I’ve been counting AES lately by SOC HLGT and PT with several thousand AES with no problem, granted that ain’t millions. When running on a multi processor system using CLASS instead of BY, MEANS/SUMMARY can produce astounding performance.

I would not eschew CLASS just because I “think” it might not work, I would find out first.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 8 replies
  • 1430 views
  • 0 likes
  • 4 in conversation