BookmarkSubscribeRSS Feed
deleted_user
Not applicable
How do I identify the latest date in a date variable of a dataset? Is it possible to do it without sorting?
Thanks,
TJ
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Pass the file in a DATA step using SET statement, also use a RETAIN statement with the MAX function to keep track of the maximum value encountered for your date variable (assigning a new temporary or permanent SAS variable.

What's unclear is how you intend to use this information, either during the SAS session or after. So, the next question to pose back to the OP: what do you want to do with this information once you have it derived in a DATA step?

Also, PROC SQL could be used to perform a similar process.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Thanks for your reply. I thought of MAX, but forgot retain. I actually need to have the Max value during the whole datastep, so I decided that the data did need to be sorted in descending order.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest using a SAS view - no need to sort the data, regardless. Just keep track of the MAX value encountered. Okay, so sorting the data does permit you to select the first obs from the sorted-output file. I'd submit that there will be less resource usage if you use a SAS view, pass the file as-is, where-is. However, it's still unclear what you intend to do with the max-value -- as was previously asked.

Good luck.

Scott Barry
SBBWorks, Inc.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1299 views
  • 0 likes
  • 2 in conversation