Hello, i want to ask a question about two options of yrdif function : 'ACT/ACT' vs 'AGE'
yr_act_act = yrdif(startdate, enddate, 'act/act');
yr_age = yrdif(startdate, enddate, 'AGE');
1. 'Age' options is most accurate, it takes into account for example, leap year, right?
2. What is difference between two options?
Thank you
From the example given in the documentation, ACT/ACT and AGE seem to be equivalent.
But according to this:
one should use AGE for age calculations.
Hi @AlexeyS
This is very weird indeed.
In the documentation, the calculation seems to be the same, i.e. SAS takes into account leap years.
However, the result is not exactly the same (even if the difference is slight and in the decimal part):
SAS recommends the us of 'AGE' to calculates AGES.
The decimal difference is explained by the handling of the leap years, as the documentation states:
Year 2000 is a leap year.
data ONEDAY;
YEAR_FRACTION=yrdif('01jan2000'd,'02jan2000'd,'age'); output;
YEAR_FRACTION=1/365; output;
YEAR_FRACTION=yrdif('01jan2000'd,'02jan2000'd,'act/act'); output;
YEAR_FRACTION=1/366; output;
run;
YEAR_FRACTION |
---|
.002739726 |
.002739726 |
.002732240 |
.002732240 |
@ed_sas_member 2020 is a leap year too. If you run your exact same test next year, using the today() function, there will be no difference.
data ONEDAY;
YEAR_FRACTION=yrdif('01jan2000'd,'02jan2000'd,'age'); output;
YEAR_FRACTION=1/365; output;
YEAR_FRACTION=yrdif('01jan2000'd,'02jan2000'd,'act/act'); output;
YEAR_FRACTION=1/366; output;
run;
YEAR_FRACTION |
---|
.002739726 |
.002739726 |
.002732240 |
.002732240 |
Hello @AlexeyS,
The algorithm of ACT/ACT is described in Calculations That Use ACT/ACT Basis: "YRDIF=n365/365.0 + n366/366.0" with the numbers n365 and n366 of days (between start and end date) in a 365-day year or 366-day year, respectively. It should be noted that "between" means including the start date, but excluding the end date. That is, the date difference increases by 1/366 or 1/365 when the end date advances by one day, depending on whether the day before the new end date (i.e., the old end date) falls in a leap year or not.
The subsequent section Computing a Person’s Age is less precise, though. It appears that YRDIF(...,'AGE') also uses two different increments when the end date advances by one day: 0 (!) if the end date is a leap day (February 29th), else 1/365. That is, the result is 1/365 times the date difference reduced by the number of leap days greater than start date and less than or equal to end date.
As a consequence, both algorithms should produce identical results if only complete leap years, if any, are involved because a complete leap year is counted as 1 year by both algorithms. More precisely, the results should be the same
In all other cases the date interval contains an incomplete leap year, which leads to different results (differences in both directions) because of the different increments (1/366 vs. 0 or 1/365).
In addition to the discrepancies due to the different algorithms we see tiny differences (like 4.44E-16) due to rounding errors. This must be considered (e.g., using the ROUND function with rounding unit 1e-9) in comparisons of results.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.