Help using Base SAS procedures

Maximum date in a SAS dataset

Reply
N/A
Posts: 0

Maximum date in a SAS dataset

How do I identify the latest date in a date variable of a dataset? Is it possible to do it without sorting?
Thanks,
TJ
Super Contributor
Super Contributor
Posts: 3,174

Re: Maximum date in a SAS dataset

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.
N/A
Posts: 0

Re: Maximum date in a SAS dataset

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: Maximum date in a SAS dataset

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.
Ask a Question
Discussion stats
  • 3 replies
  • 109 views
  • 0 likes
  • 2 in conversation