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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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