SAS Enterprise Guide

Desktop productivity for business analysts and programmers
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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