YRDIF Function
Returns the difference in years between two dates according to specified day count conventions; returns a person’s age.
| Categories: | Date and Time |
| CAS |
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 is computed.
Details
Using YRDIF in Financial Applications
The Basics
Calculations That Use ACT/ACT Basis
Computing a Person’s Age
Examples
Example 1: Calculating a Difference in Years Based on 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;
y30360=11.333333333 yactact=11.336986301 yact360=11.502777778 yact365=11.345205479
Example 2: Calculating a Person’s Age
data _null_; sdate='16oct1998'd; edate='16feb2010'd; age=yrdif(sdate, edate, 'AGE'); put age= 'years'; run;
age=11.336986301 years