BookmarkSubscribeRSS Feed
TCy
Calcite | Level 5 TCy
Calcite | Level 5

Help!

I need to find the difference between 2 time stamps. If I have the columns Task and TimeStamp, I'm looking for the difference between TimeStamp of row n & of row (n-1). I can't do this in query builder, as I learned... I know that I can use the dif function or a lag function, but where would I put this? Would I need to make a new program to pull the needed data from the existing table and then make the calculation?

I wish I could just use Excel!! Any help would be GREATLY appreciated!

1 REPLY 1
Keith
Obsidian | Level 7

The DIF function is what you need here.  You put it in a data step, such as :

data want;

set have;

by timestamp;

time_dif=dif(timestamp);

run;

This assumes that the dataset is sorted in timestamp order and that you don't have any other BY variables (e.g. Task).  I put the BY statement in so that the step would fail if the data wasn't sorted by timestamp.  You have to be careful if you are using IF or WHERE statements with DIF and LAG, it's worth reading the following article which describes the pitfalls you may encounter and how to resolve them.


www.nesug.org/proceedings/nesug07/cc/cc33.pdf

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1 reply
  • 719 views
  • 0 likes
  • 2 in conversation