Functions and CALL Routines

# INTFIT Function

Returns a time interval that is aligned between two dates.
 Category: Date and Time

## Syntax

 INTFIT(argument-1, argument-2, 'type')

### Arguments

argument

specifies a SAS expression that represents a SAS date or datetime value, or an observation.

 Tip: Observation numbers are more likely to be used as arguments if date or datetime values are not available.
'type'

specifies whether the arguments are SAS date values, datetime values, or observations.

The following values for type are valid:

 d specifies that argument-1 and argument-2 are date values. dt specifies that argument-1 and argument-2 are datetime values. obs specifies that argument-1 and argument-2 are observations.

The INTFIT function returns the most likely time interval based on two dates, datetime values, or observations that have been aligned within an interval. INTFIT assumes that the alignment value is SAME, which specifies that the date is aligned to the same calendar date with the corresponding interval increment. For more information about the alignment argument, see INTNX Function.

If the arguments that are used with INTFIT are observations, you can determine the cycle of an occurrence by using observation numbers. In the following example, the first two arguments of INTFIT are observation numbers, and the type argument is obs . If Jason used the gym the first time and the 25th time that a researcher recorded data, you could determine the interval by using the following statement: interval=intfit(1,25,'obs'); . In this case, the value of interval is OBS24.2.

For information about time series, see the SAS/ETS User's Guide.

The INTFIT function can also be used with calendar intervals from the retail industry. These intervals are ISO 8601 compliant. For more information, see Retail Calendar Intervals: ISO 8601 Compliant in SAS Language Reference: Concepts.

### Example 1: Finding Intervals That Are Aligned between Two Dates

The following example shows the intervals that are aligned between two dates. The type argument in this example identifies the input as date values.

```options pageno=1 nodate ls=80 ps=64;

data a;
length interval \$20;
date1='01jan06'd;
do i=1 to 25;
date2=intnx('day', date1, i);
interval=intfit(date1, date2, 'd');
output;
end;
format date1 date2 date.;
run;

proc print data=a;
run;```

```                                 The SAS System                                1

Obs    interval     date1      i     date2

1    DAY         01JAN06     1    02JAN06
2    DAY2        01JAN06     2    03JAN06
3    DAY3.3      01JAN06     3    04JAN06
4    DAY4.3      01JAN06     4    05JAN06
5    DAY5.3      01JAN06     5    06JAN06
6    DAY6.3      01JAN06     6    07JAN06
7    WEEK        01JAN06     7    08JAN06
8    DAY8.3      01JAN06     8    09JAN06
9    DAY9.9      01JAN06     9    10JAN06
10    TENDAY      01JAN06    10    11JAN06
11    DAY11.6     01JAN06    11    12JAN06
12    DAY12.3     01JAN06    12    13JAN06
13    DAY13.7     01JAN06    13    14JAN06
14    WEEK2.8     01JAN06    14    15JAN06
15    SEMIMON     01JAN06    15    16JAN06
16    DAY16.3     01JAN06    16    17JAN06
17    DAY17.7     01JAN06    17    18JAN06
18    DAY18.9     01JAN06    18    19JAN06
19    DAY19.7     01JAN06    19    20JAN06
20    TENDAY2     01JAN06    20    21JAN06
21    WEEK3.8     01JAN06    21    22JAN06
22    DAY22.17    01JAN06    22    23JAN06
23    DAY23.13    01JAN06    23    24JAN06
24    DAY24.3     01JAN06    24    25JAN06
25    DAY25.3     01JAN06    25    26JAN06```

The output shows that if the increment value is one day, then the result of the INTFIT function is DAY. If the increment value is two days, then the result of the INTFIT function is DAY2. If the increment value is three days, then the result is DAY3.3, with a shift index of 3. (If the two input dates are a Friday and a Monday, then the result is WEEKDAY.) If the increment value is seven days, then the result is WEEK.

### Example 2: Finding Intervals That Are Aligned between Two Dates When the Dates Are Identified As Observations

The following example shows the intervals that are aligned between two dates. The type argument in this example identifies the input as observations.

```options pageno=1 nodate ls=80 ps=64;

data a;
length interval \$20;
date1='01jan06'd;
do i=1 to 25;
date2=intnx('day', date1, i);
interval=intfit(date1, date2, 'obs');
output;
end;
format date1 date2 date.;
run;

proc print data=a;
run;```

```                                 The SAS System                                1

Obs    interval     date1      i     date2

1    OBS         01JAN06     1    02JAN06
2    OBS2        01JAN06     2    03JAN06
3    OBS3.3      01JAN06     3    04JAN06
4    OBS4.3      01JAN06     4    05JAN06
5    OBS5.3      01JAN06     5    06JAN06
6    OBS6.3      01JAN06     6    07JAN06
7    OBS7.3      01JAN06     7    08JAN06
8    OBS8.3      01JAN06     8    09JAN06
9    OBS9.9      01JAN06     9    10JAN06
10    OBS10.3     01JAN06    10    11JAN06
11    OBS11.6     01JAN06    11    12JAN06
12    OBS12.3     01JAN06    12    13JAN06
13    OBS13.7     01JAN06    13    14JAN06
14    OBS14.3     01JAN06    14    15JAN06
15    OBS15.3     01JAN06    15    16JAN06
16    OBS16.3     01JAN06    16    17JAN06
17    OBS17.7     01JAN06    17    18JAN06
18    OBS18.9     01JAN06    18    19JAN06
19    OBS19.7     01JAN06    19    20JAN06
20    OBS20.3     01JAN06    20    21JAN06
21    OBS21.3     01JAN06    21    22JAN06
22    OBS22.17    01JAN06    22    23JAN06
23    OBS23.13    01JAN06    23    24JAN06
24    OBS24.3     01JAN06    24    25JAN06
25    OBS25.3     01JAN06    25    26JAN06```

 Functions:

 Previous Page | Next Page | Top of Page