turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- INTCK Function and Rounding

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-10-2013 05:05 PM

Hi all,

Does anyone out there know how the INTCK function rounds when calculating hours between two datetimes? I've tried determing by looking at results of using it, but it's not clear. For example, if five mintues has gone by it shows 0, but if 45 have gone by it shows 1. Is it rounding at the 30 minute mark? No guesses please this is for work so I need a concrete answer if anyone has one. Thanks!!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-10-2013 05:37 PM

According to the documentation it isn't rounding at all but, rather, simply counting the number of boundaries. Thus, if you are using it for hours, 9:59 to 10:00 would result in 1. You can easily test that to be certain that is the way it is functioning.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-10-2013 05:39 PM

I thought it only counted full hours:

data test ;

hours=intck('hour','01jan2009:00:00:00'dt,'01jan2009:00:45:00'dt);

run ;

equals 0 when I run it.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-10-2013 05:48 PM

Steve,

Boundaries, not hours per se. Try the following:

data test ;

hours=intck('hour','01jan2009:23:59:59'dt,'02jan2009:00:00:00'dt);

run ;

Hours will result in a value of 1

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-10-2013 05:52 PM

Ahh I see

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-10-2013 05:45 PM

The default method of calculation in INTCK counts the number of crossed interval boundaries between two datetimes. For example,

**data _null_;**

**D1 = '14:00:00't;**

**D2 = '14:59:00't;**

**D3 = '15:00:00't;**

**D1_D2 = intck("HOUR", D1, D2);**

**D1_D3 = intck("HOUR", D1, D3);**

**D2_D3 = intck("HOUR", D2, D3);**

**put (D1 D2) (=:time5.) D1_D2= "No hour interval boundary crossed";**

**put (D1 D3) (=:time5.) D1_D3= "15:00 hour boundary crossed";**

**put (D2 D3) (=:time5.) D2_D3= "15:00 hour boundary crossed";**

**run;**

**D1=14:00 D2=14:59 D1_D2=0 No hour interval boundary crossed**

**D1=14:00 D3=15:00 D1_D3=1 15:00 hour boundary crossed**

**D2=14:59 D3=15:00 D2_D3=1 15:00 hour boundary crossed**

Read the documentation for another method it can use to count boundaries.

PG

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-11-2013 09:45 AM

Thanks everyone. I've checked this out with my data and it matches up, it is in fact just counting the difference between the hour boundaries. Thank you!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-11-2013 02:48 PM

Note that if you use 'C' argument at the end, it will count continuously rather than across boundaries. (This is what PGStats was obliquely referring to.)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-11-2013 03:25 PM

: Joe, correct, but still just counting boundaries crossed. Interestingly, the documentation is wrong. It states that using 'C' causes the function to begin with your start date. Actually, it appears to be "your start date or, if a datetime is provided, the starting date/time".

data test ;

hours=intck('hour','01jan2009:23:59:59'dt,'02jan2009:00:00:00'dt,'C');

run ;

produces 0

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-11-2013 03:33 PM

I'm not sure what the problem is, there. That's what you'd expect from that (perhaps the doc can be more clear, certainly). With continuous, it's counting boundaries, true, but how else would you calculate the number of days between something? You'd have to do some sort of boundary. The point with continuous (which is horribly named; INTNX 'same'/'s' makes far more sense) is that it counts truly the number of [whatevers] since [exact date or datetime], not the number of crossings of an unrelated boundary (ie, midnight, or Jan 1, or whatnot.)