### Counting Time Intervals

Use the INTCK function to count the number of interval boundaries between two dates.

Note that the INTCK function counts the number of times the beginning of an interval is reached in moving from the first date to the second. It does not count the number of complete intervals between two dates. Following are two examples:

• The function INTCK(’MONTH’,’1JAN1991’D,’31JAN1991’D) returns 0, since the two dates are within the same month.

• The function INTCK(’MONTH’,’31JAN1991’D,’1FEB1991’D) returns 1, since the two dates lie in different months that are one month apart.

When the first date is later than the second date, INTCK returns a negative count. For example, the function INTCK(’MONTH’,’1FEB1991’D,’31JAN1991’D) returns –1.

The following example shows how to use the INTCK function with shifted interval specifications to count the number of Sundays, Mondays, Tuesdays, and so forth, in each month. The variables NSUNDAY, NMONDAY, NTUESDAY, and so forth, are added to the USCPI data set.

```data uscpi;
set uscpi;
d0 = intnx( 'month', date, 0 ) - 1;
d1 = intnx( 'month', date, 1 ) - 1;
nSunday  = intck( 'week.1', d0, d1 );
nMonday  = intck( 'week.2', d0, d1 );
nTuesday = intck( 'week.3', d0, d1 );
nWedday  = intck( 'week.4', d0, d1 );
nThurday = intck( 'week.5', d0, d1 );
nFriday  = intck( 'week.6', d0, d1 );
nSatday  = intck( 'week.7', d0, d1 );
drop d0 d1;
run;
```

Since the INTCK function counts the number of interval beginning dates between two dates, the number of Sundays is computed by counting the number of week boundaries between the last day of the previous month and the last day of the current month. To count Mondays, Tuesdays, and so forth, shifted week intervals are used. The interval type WEEK.2 specifies weekly intervals starting on Mondays, WEEK.3 specifies weeks starting on Tuesdays, and so forth.