BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Andalusia
Obsidian | Level 7

I tried to calculate Diff by doing computed column > Advanced expression and then `datetime() - t1.datetime / 60 `. Diff is actually the difference between SAS_update and DateTime, SAS_Update is just the lastruntime (datetime())

 

This is what I got:

Andalusia_0-1634707532713.png
I get a very weird value but I expected Diff to have value -1 because there is a a difference of -1 minutes between them SAS_update and DateTime...

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Your approach is OK, but you need to add parentheses. Without them, SAS performs division first, then subtraction. Use parentheses to force the subtraction to take place first.

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

Use the function intck.

Datetime-variables are, without a format, the number of seconds passed from 1Jan1960 to the actual datetime. The function takes care of the details, if you need the difference in minutes, then use "dtminute" as interval.

Andalusia
Obsidian | Level 7
Could you show an example?
Kurt_Bremser
Super User

@Andalusia wrote:
Could you show an example?

Looks like this:

intck('minute',t1.datetime,datetime(),"c")

The "c" (for continuous) means that difference / 60 is used, and not the count of minute boundaries between the two values (90 seconds difference can turn out to be 2 minutes if the default is used).

For reference, run this:

data _null_;
time = datetime();
rc = sleep (119,1);
diff1 = intck('minute',time,datetime(),"c");
diff2 = intck('minute',time,datetime());
put _all_;
run;
Astounding
PROC Star
Your approach is OK, but you need to add parentheses. Without them, SAS performs division first, then subtraction. Use parentheses to force the subtraction to take place first.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 4 replies
  • 1322 views
  • 0 likes
  • 4 in conversation