YRDIF Function

Returns the difference in years between two dates according to specified day count conventions; returns a person’s age.

Category: Date and Time

Syntax

Required Arguments

start-date

specifies a SAS date value that identifies the starting date.

end-date

specifies a SAS date value that identifies the ending date.

Optional Argument

basis

identifies a character constant or variable that describes how SAS calculates a date difference or a person’s age. The following character strings are valid:

'30/360'

specifies a 30-day month and a 360-day year in calculating the number of years. Each month is considered to have 30 days, and each year 360 days, regardless of the actual number of days in each month or year.

Alias '360'
Tip If either date falls at the end of a month, it is treated as if it were the last day of a 30-day month.

'ACT/ACT'

uses the actual number of days between dates in calculating the number of years. SAS calculates this value as the number of days that fall in 365-day years divided by 365 plus the number of days that fall in 366-day years divided by 366.

Alias 'Actual'

'ACT/360'

uses the actual number of days between dates in calculating the number of years. SAS calculates this value as the number of days divided by 360, regardless of the actual number of days in each year.

'ACT/365'

uses the actual number of days between dates in calculating the number of years. SAS calculates this value as the number of days divided by 365, regardless of the actual number of days in each year.

'AGE'

specifies that a person’s age will be computed.

If you do not specify a third argument, AGE becomes the default value for basis.

Details

Using YRDIF in Financial Applications

The Basics

The YRDIF function can be used in calculating interest for fixed income securities when the third argument, basis, is present. YRDIF returns the difference between two dates according to specified day count conventions.

Calculations That Use ACT/ACT Basis

In YRDIF calculations that use the ACT/ACT basis, both a 365–day year and 366–day year are taken into account. For example, if n365 equals the number of days between the start and end dates in a 365–day year, and n366 equals the number of days between the start and end dates in a 366–day year, the YRDIF calculation is computed as YRDIF=n365/365.0 + n366/366.0. This calculation corresponds to the commonly understood ACT/ACT day count basis that is documented in the financial literature. The values for basis also includes 30/360, ACT/360, and ACT/365. Each has well-defined meanings that must be adhered to in calculating interest payments for specific financial instruments.

Computing a Person’s Age

The YRDIF function can compute a person’s age. The first two arguments, start-date and end-date, are required. If the value of basis is AGE, then YRDIF computes the age. The age computation takes into account leap years. No other values for basis are valid when computing a person’s age.

Examples

Example 1: Calculating a Difference in Years Based on Basis

In the following example, YRDIF returns the difference in years between two dates based on each of the options for basis.
data _null_;
   sdate='16oct1998'd;
   edate='16feb2010'd;
   y30360=yrdif(sdate, edate, '30/360');
   yactact=yrdif(sdate, edate, 'ACT/ACT');
   yact360=yrdif(sdate, edate, 'ACT/360');
   yact365=yrdif(sdate, edate, 'ACT/365');
   put y30360= / yactact= / yact360= / yact365= ;
run;
SAS writes the following output to the log:
y30360=11.333333333
yactact=11.336986301
yact360=11.502777778
yact365=11.345205479

Example 2: Calculating a Person’s Age

You can calculate a person’s age by using three arguments in the YRDIF function. The third argument, basis, must have a value of AGE:
data _null_;
   sdate='16oct1998'd;
   edate='16feb2010'd;
   age=yrdif(sdate, edate, 'AGE');
   put age= 'years';
run;
SAS writes the following output to the log:
age=11.336986301 years

See Also

Functions:

References

“Day count convention.” Wikipedia, 2010. Available Day count convention.
ISDA International Swaps and Derivatives Association, Inc. “EMU and Market Conventions: Recent Developments.” 1998. Wikipedia. Available EMU and Market Conventions: Recent Developments.
Mayle, Jan. 1994. Standard Securities Calculation Methods – Fixed Income Securities Formulas for Analytic Measures. Vol. 2. NY, NY: Securities Industry Association.