BookmarkSubscribeRSS Feed
Sean_OConnor
Obsidian | Level 7

Folks,

 

I have a dataset of transactions for people and I need to identify which ones are the latest. I have a timestamp variable which we can call time_stamp and I have an ID variable which we call ID.

 

Timestamp is numeric with larger values meaning its more recent to the system. 

 

So I did to run some code that outputs the latest value for an individual when the timestamp is the largest for that id.

 

Could anyone supply and ideas please?

2 REPLIES 2
Reeza
Super User
Sort ascending or descending and use FIRST or LAST respectively to get the first or last record for each ID.

proc sort data=have;
by ID time_stamp;
run;

data want;
set have;
by id time_stamp;
if last.id;
run;
Reeza
Super User
Or use the MAX() function in SQL or PROC MEANS.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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