BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mdavidson
Quartz | Level 8
I have two datetime fields and want to calculate the difference in minutes between the two fields. I don't believe the DATDIF function will return minutes, will it? Is there another function that I can use? So far I haven't had any luck searching the SAS EG help or the web....

Thanks in advance.
1 ACCEPTED SOLUTION

Accepted Solutions
Doc_Duke
Rhodochrosite | Level 12

@mdavidson wrote:
got it: INTCK('minute',field1,field2 )

 

INTCK can give results that aren't what you want in all cases, as it counts from the beginning of the interval (see the Details section of the documentation). If your data are recorded to the minute, it won't matter. If your data are recorded to the second, it might.

As datetime variables are recorded in seconds, an alternative is to use the fact that there are 60 seconds in a minutes and just do the arithmetic directly

(datetime2 - datetime1)/60 provides minutes with decimal fractions.
FLOOR( (datetime2 - datetime1)/60 ) provides the whole minute durations.

For instance, 12:01:50 to 12:02:10 is 1 using INTCK, 0.333 using the decimal minutes, and 0 using the FLOOR version.

View solution in original post

3 REPLIES 3
mdavidson
Quartz | Level 8
Got it: INTCK('minute',field1,field2 )
Doc_Duke
Rhodochrosite | Level 12

@mdavidson wrote:
got it: INTCK('minute',field1,field2 )

 

INTCK can give results that aren't what you want in all cases, as it counts from the beginning of the interval (see the Details section of the documentation). If your data are recorded to the minute, it won't matter. If your data are recorded to the second, it might.

As datetime variables are recorded in seconds, an alternative is to use the fact that there are 60 seconds in a minutes and just do the arithmetic directly

(datetime2 - datetime1)/60 provides minutes with decimal fractions.
FLOOR( (datetime2 - datetime1)/60 ) provides the whole minute durations.

For instance, 12:01:50 to 12:02:10 is 1 using INTCK, 0.333 using the decimal minutes, and 0 using the FLOOR version.

Mantagon
Calcite | Level 5
This is exactly what I wanted. Thanks very much!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 68268 views
  • 5 likes
  • 3 in conversation