Solved
Contributor
Posts: 62

# compute age from two dates

Hi ,

I need to  calculate age at graduation.  I was wondering if  any of  the two methods below are appropriate and take care  leap years as well.

Thank you very much

Accepted Solutions
Solution
‎06-19-2016 06:29 PM
Posts: 5,526

## Re: compute age from two dates

Isn't it a bit strange that one would have to resort to datestring formatting to calculate an age? The matter depends on a specific case: if you are born on the 29th of February (in a leap year, obviously), do you celebrate your birthday on the 28th of February or on the first of March, during non-leap years? If your answer is the former then your age is

intck("year", dob, event, "continuous")  /* birthday on the 28th during non-leap years */

intck('year', dob, event) - (put(dob, mmddyy4.) > put(event, mmddyy4.))  /* birthday on March 1st during non-leap years */

Another option is to use function INT(YRDIF(dob, event, "AGE")). It considers that you will celebrate your birthday on the 28th, even on leap years.

PG

All Replies
Super User
Posts: 23,700

## Re: compute age from two dates

[ Edited ]

The recommended formula:

``age = intck('year',dob,event) - (put(dob,mmddyy4.) > put(event,mmddyy4.)) ;``

https://communities.sas.com/t5/SAS-in-Health-Care-Related/Calculating-Age-But-Not-Rounding-Up/td-p/1...

Solution
‎06-19-2016 06:29 PM
Posts: 5,526

## Re: compute age from two dates

Isn't it a bit strange that one would have to resort to datestring formatting to calculate an age? The matter depends on a specific case: if you are born on the 29th of February (in a leap year, obviously), do you celebrate your birthday on the 28th of February or on the first of March, during non-leap years? If your answer is the former then your age is

intck("year", dob, event, "continuous")  /* birthday on the 28th during non-leap years */

intck('year', dob, event) - (put(dob, mmddyy4.) > put(event, mmddyy4.))  /* birthday on March 1st during non-leap years */

Another option is to use function INT(YRDIF(dob, event, "AGE")). It considers that you will celebrate your birthday on the 28th, even on leap years.

PG
Contributor
Posts: 62

## Re: compute age from two dates

This makes a lot sense.Thanks a lot!

Contributor
Posts: 62

## Re: compute age from two dates

Great! Thank you very much

Contributor
Posts: 62

## Re: compute age from two dates

Great! Thank you very much Reeza
🔒 This topic is solved and locked.