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

Hello,

I am working with a dataset that has a few million records, and instead of sorting by id and visit date, then using a data step to take the first. and last. visit dates for each id I would be interested in a more efficient way to get the data. The proc sort on the dataset takes forever. Any help would be appreciated. Thanks!

-Steve

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I would be tempted to use PROC SUMMARY and CLASS statements.

Something like:

proc summary data =have ;

     class ID;

     var VisitDate;

     output out=want max min /autoname;

run;

or

Proc sql;

     create table want as

     select id, min(visitdate) as firstdate, max(visitdate) as lastdate

     from have

     group by id;

quit;

View solution in original post

3 REPLIES 3
ballardw
Super User

I would be tempted to use PROC SUMMARY and CLASS statements.

Something like:

proc summary data =have ;

     class ID;

     var VisitDate;

     output out=want max min /autoname;

run;

or

Proc sql;

     create table want as

     select id, min(visitdate) as firstdate, max(visitdate) as lastdate

     from have

     group by id;

quit;

Haikuo
Onyx | Level 15

If your source data is something other than SAS table, say Oracle, SQL server, then you will have an option doing it using pass-thru. Other than that, you are stuck with Proc Sort. I doubt if Hash table could help, but first you need to make sure your whole table can be fitted into your RAM, and even if it can, I suspect that the Hash sorting would be more efficient than Proc sort.

my 2cents,

Haikuo

browste
Calcite | Level 5

Thanks so much ballardw, both of those are much, much quicker. I really appreciate it!

-Steve

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
  • 1207 views
  • 0 likes
  • 3 in conversation