Calculate Age Using Date of Birth in SAS | Free Tool & Code


SAS Age Calculator (from Date of Birth)

Enter a date of birth and a calculation date to find the precise age in years, months, and days. The calculator will also generate the corresponding SAS code to perform the same calculation.



The starting date for the age calculation.

Please enter a valid date.



The date on which the age is calculated. Defaults to today.

Please enter a valid date.

What is Calculating Age in SAS?

To calculate age using date of birth in SAS is to determine the time duration between a person’s birth date and a specific reference date, using SAS programming functions. This is a fundamental task in data analysis, especially in fields like demography, healthcare, and finance where age is a critical variable. SAS provides robust functions like INTCK() and YRDIF() specifically designed for accurate date calculations, which account for complexities like leap years.

Unlike simple subtraction, these functions correctly interpret date values to provide age in whole years, fractional years, or other time intervals. This calculator not only gives you the age but also generates the exact SAS syntax, helping both new and experienced SAS users to implement this logic in their data processing workflows. Understanding how to correctly manipulate data in SAS is key to reliable analysis.

SAS Age Calculation Formulas and Explanation

SAS offers two primary functions to calculate age. The choice between them depends on the required precision.

1. The INTCK() Function

The INTCK() function (Interval Check) counts the number of interval boundaries (like the start of a year) crossed between two dates. To get a person’s age in completed years, you use the ‘YEAR’ interval.

Formula: age = INTCK('YEAR', birth_date, calculation_date);

2. The YRDIF() Function

The YRDIF() function (Year Difference) provides a more precise calculation. When used with the ‘AGE’ method, it calculates the age accurately, similar to how a person states their age. It returns a fractional value representing the completed years and the fraction of the next year.

Formula: age = YRDIF(birth_date, calculation_date, 'AGE');

Description of variables used in SAS age calculation.
Variable Meaning Unit (SAS Type) Typical Range
birth_date The starting date (e.g., date of birth). SAS Date Value Any valid historical date.
calculation_date The ending date for the calculation. SAS Date Value Any valid date, usually today’s date.
‘AGE’ The method for calculation in YRDIF. Text String (Parameter) ‘AGE’, ‘ACT/ACT’, etc.
‘YEAR’ The interval for calculation in INTCK. Text String (Parameter) ‘YEAR’, ‘MONTH’, ‘DAY’, etc.

Practical Examples

Example 1: Standard Age Calculation

Let’s say we need to calculate the age of a person for an insurance policy application.

  • Input – Date of Birth: June 15, 1985
  • Input – Calculation Date: January 26, 2026
  • Result: The person is 40 years, 7 months, and 11 days old.
  • SAS Logic (YRDIF): YRDIF('15JUN1985'd, '26JAN2026'd, 'AGE') would yield approximately 40.61.

Example 2: Calculating Age at a Past Event

Suppose you need to know how old an individual was when they graduated college.

  • Input – Date of Birth: September 30, 2001
  • Input – Calculation Date (Graduation): May 20, 2023
  • Result: The person was 21 years, 7 months, and 20 days old at graduation.
  • SAS Logic (INTCK): INTCK('YEAR', '30SEP2001'd, '20MAY2023'd) would yield 22, because 22 year-boundaries have been crossed. This shows why YRDIF is often preferred for a person’s actual age. A guide on advanced SAS date functions can provide more detail.

How to Use This SAS Age Calculator

This tool simplifies the process to calculate age using date of birth in SAS. Follow these steps for an accurate result and ready-to-use code.

  1. Enter Date of Birth: Use the date picker to select the year, month, and day of birth.
  2. Enter Calculation Date: Select the “as of” date. This field automatically defaults to today’s date but can be changed to any past or future date.
  3. Review the Results: The calculator instantly displays the age in three formats: a detailed breakdown (years, months, days), the total number of months, and the total number of days.
  4. Copy the SAS Code: The corresponding SAS code is generated in the text box below the results. You can use the “Copy Code” button to transfer it directly into your SAS editor. The code shows both YRDIF and INTCK methods.

Key Factors That Affect Age Calculation in SAS

When you calculate age using date of birth in SAS, several factors can influence the outcome. Being aware of them is crucial for data integrity. For those working with large datasets, understanding SAS performance optimization is also vital.

  • Function Choice (INTCK vs. YRDIF): INTCK counts boundaries, which can be misleading. YRDIF(..., 'AGE') is specifically designed to compute age in the conventional sense and is almost always the better choice.
  • The ‘AGE’ Parameter in YRDIF: This third parameter is critical. Omitting it or using a different basis (like ‘ACT/ACT’) will calculate a simple year fraction, not a person’s age.
  • Leap Years: Both INTCK and YRDIF automatically and correctly handle leap years, which is a major advantage over manual calculations.
  • Date Representation: SAS stores dates as the number of days since January 1, 1960. Your input data must be in a format SAS can read (e.g., DDMMYY10., MMDDYY10.) before any calculation can be performed. The calculator handles this conversion for you.
  • Time of Day: SAS date values do not store time. For age calculation, this is generally not an issue. However, if using DATETIME values, you would need to convert them to dates first using the DATEPART() function.
  • Endpoint Inclusion: The INTCK function’s counting method can sometimes be ambiguous. It’s important to test with edge cases (like birthdays) to ensure the logic matches your business requirements.

Frequently Asked Questions (FAQ)

1. What is the most accurate function to calculate age in SAS?

The YRDIF(start_date, end_date, 'AGE') function is the most accurate and recommended method. It correctly computes a person’s age by considering the full birth date, unlike INTCK which can be off by almost a year.

2. How does the YRDIF ‘AGE’ parameter work?

It calculates the difference by taking the number of full years passed, then adds the fraction of the next year that has elapsed. It correctly handles the fact that you don’t turn a year older until your birthday.

3. Can I calculate age in total months or days?

Yes. You can use INTCK('MONTH', start_date, end_date) or INTCK('DAY', start_date, end_date). The calculator provides these intermediate values for your convenience.

4. Why does INTCK(‘YEAR’, …) sometimes give a different result?

INTCK simply counts how many times January 1st has passed between the two dates. For example, from Dec 31, 2024 to Jan 1, 2025, it would count 1 year, even though only one day has passed. This makes it unsuitable for calculating a person’s actual age. For help with these nuances, a SAS consultant can be invaluable.

5. How do I handle missing birth dates in my data?

In SAS, missing date values will result in a missing age. You must implement data cleaning and imputation logic to handle these cases before you calculate age. For example, you might exclude them or impute a mean/median date if appropriate.

6. Does this calculator handle leap years correctly?

Yes, all calculations are based on JavaScript’s Date object, which, like SAS’s internal date handling, correctly accounts for leap years (e.g., February 29th).

7. How can I format the fractional age from YRDIF to two decimal places?

You can use the ROUND() function in SAS, like so: age = ROUND(YRDIF(dob, today, 'AGE'), 0.01);. This will round the result to the nearest hundredth.

8. Can I use this code in a SAS macro?

Absolutely. The generated code is standard SAS syntax and can be easily incorporated into a reusable SAS macro to calculate age across different datasets and projects.

© 2026 Your Company Name. All Rights Reserved.


Leave a Reply

Your email address will not be published. Required fields are marked *