Contributor
Posts: 27

# Calculate age

Hi all,
How can I calculate the age of patients from the date of birth. Thanks in advance
Frequent Contributor
Posts: 139

## Re: Calculate age

a quick google search of calculate age in sas pointed to this

http://support.sas.com/kb/24/567.html
Frequent Contributor
Posts: 77

## Re: Calculate age

Hello dash, darrylovia, and everyone,

The example at http://support.sas.com/kb/24/567.html (Sample 24567: Calculate a person's age) involves calculation of number of months in the interval between birthday and current date, and the number of years as #months/12 etc.

I used to calculate the age as age=int((current-bday)/365.25). Using the data from the example I got the exact same values for age:

data birth;
input name \$ bday :mmddyy10. current :mmddyy10.;
datalines;
Miguel 12/31/1973 12/14/2004
Joe 02/28/1976 12/14/2004
Rutger 03/29/1976 12/14/2004
Broguen 03/01/1976 12/14/2004
Susan 12/12/1976 12/14/2004
Michael 02/14/1971 12/14/2004
LeCe 11/09/1967 12/14/2004
Hans 07/02/1955 12/14/2004
Lou 07/30/1960 12/14/2004
;

data age;
set birth;
if bday ne . and current ne .
then age=int((current-bday)/365.25);
else age=.;
run;

proc print;
format bday current worddate20.;
run;

I was wondering if the {#months/12} has any advantages over what seems to me much simpler {#days/365.25} method. Can anybody tell me what are the pitfalls with {#days/365.25}?
Super Contributor
Posts: 365

## Re: Calculate age

Hello StatsPlank,

I made some testing and found that these formulas gave different ages on at least two following examples:

1. Current=10Mar2011 Bday=01Mar2010
age(based on #month)=1
age(based on #days) = 0

2. Current=10Mar2011 Bday=01Mar2009
age(based on #month)=1
age(based on #days) = 2

Sincerely,
SPR
Super Contributor
Posts: 3,176

## Re: Calculate age

There are well-documented SAS functions for calculating AGE within the SAS system, as well as dealing with DATE and DATETIME type SAS variables. Very specifically, refer to the INTCK function in the SAS Language DOC, also with the SAS support site and supplemental technical/conference reference material (using your favorite website and/or Internet SEARCH technique).

Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 9,040

## Re: Calculate age

Hi:
This is the paper I send to students. The answer depends on what your goal is. As the author points out...if you want to know what age someone will be in a specific year, you might use a different calculation than if you want to know what exact age someone will be on a specific day.
http://www2.sas.com/proceedings/sugi30/060-30.pdf

cynthia
Posts: 2,117

## Re: Calculate age

Deb's paper (that Cynthia@SAS references) is nice. However, credit must be given to Billy Kreuter who came up with that formula (G) back in the dark ages of SAS 5.

http://support.sas.com/kb/24/808.html

For history buffs, if you dig deep enough into the SAS-L archives, you can find the original discussion and derivation.

I prefer the (...)/365.25 for statistical modeling as it carries more information about the age. However for tabular reports, especially with large data sets, Billy's formula gets it right for all but leap-babies.

Doc Muhlbaier
Duke
SAS Super FREQ
Posts: 9,040

## Re: Calculate age

Wow, I knew that formula had been around, but didn't realize how long. Thanks, Doc for the history!

cynthia
Frequent Contributor
Posts: 77

## Re: Calculate age

Thank you everyone for contributing to this thread!

~Olya
Contributor
Posts: 35

## Re: Calculate age

``````data age(keep=age);
t_day="xxxxxxxxx"d;
d_birth="xxxxxxx'd;
age=intck("year",d_birth,t_day);
run;
ex;
data age(keep=age);t_day="27dec2017"d;d_birth="07jun1989"d;age=intck("year",d_birth,t_day);run;``````
PROC Star
Posts: 7,806

## Re: Calculate age

@rvsidhu035: The original post you responded to was from 2011. Since 9.3 I think the best way to calculate age is to use the yrdif function (see: http://www.sascommunity.org/wiki/Tips:Calculating_Exact_Age_with_the_YRDIF_Function )

Art, CEO, AnalystFinder.com

Discussion stats
• 10 replies
• 3675 views
• 0 likes
• 9 in conversation