INTFIT Function

Returns a time interval that is aligned between two dates.

Category: Date and Time

Syntax

Required 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.

Details

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 9.3 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.

Examples

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.
data a;
   length interval $20;
   date1='01jan11'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;
Interval Output from the INTFIT Function
Interval Output from the INTFIT Function
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.2, 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.
data a;
   length interval $20;
   date1='01jan11'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;
Interval Output from the INTFIT Function When Dates Are Identified as Observations
Interval Output from the INTFIT Function When Dates Are Identified as Observations

See Also