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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 888 views
  • 0 likes
  • 2 in conversation