Age Is Just a Number: Accurately Calculating Integer and ...

Age Is Just a Number: Accurately Calculating

Integer and Continuous Age

Sara Adams and Chris Colby, ICON Clinical Research, San Francisco, CA

ABSTRACT

Are you still dividing by 365.25 to calculate age? Computing integer age and

continuous age are common programming tasks¨C yet they are often done imprecisely.

By utilizing the SAS date function INTCK, it is possible to calculate integer age in one

line of code so that age increments exactly on a person¡¯s birthday. Continuous age on

an event date is calculated as the integer age plus the proportion of the year that has

elapsed since the prior birthday. This paper will present code that precisely calculates

both integer and continuous age.

INTRODUCTION

¡°Age is just a number¡± (Lexi Starling), so it might as well be an accurate one. In

common usage, age is an integer that increments exactly on a person¡¯s birthday. In

statistical analysis, age is sometimes defined as an integer (e.g. 5 years) and

sometimes as a continuous variable (e.g. 5.89 years). Given a person¡¯s date of birth

and a subsequent event date in SAS, it is straightforward to calculate how many days

the person has been alive (i.e. subtract the date of birth from the event date), but it is

more challenging to determine exactly the person¡¯s age on the event date. In this

paper, we will present a method of calculating integer age so that age increments

exactly on a person¡¯s birthday. We will also introduce an accurate method for

calculating continuous age defined as the integer age plus the fraction of the year that

has elapsed since the prior birthday.

INTEGER AGE ¨C IMPRECISE METHODS

First, we review several imprecise methods for calculating integer age. The example

code in the table assumes SAS date variables are provided for date of birth (DOB) and

for a subsequent event date.

th

Integer Age Methods*

50 Birthday for DOB = 17JUN2000

floor((eventdate-dob)/365.25)

18JUN2050

floor((eventdate-dob)/365)

05JUN2050

year(eventdate)-year(dob)

01JAN2050

floor(yrdif(dob,eventdate,'act/act'))

18JUN2050

floor(intck(¡®month¡¯,dob,eventdate)/12)

01JUN2050

* Other methods use the INT function instead of the FLOOR function. The INT function returns the

integer portion of the argument, while the FLOOR function returns the largest integer that is less than or

equal to the argument. When the evaluated argument is positive, the INT and FLOOR functions return

the same value.

As this table shows, results deviate from the correct 50th birthday (June 17, 2050)

depending on the method chosen. In an extreme case, the birthday is off by over five

months. The floor((eventdate-dob)/365) method is off by 12 days because it

does not account for the leap days that occurred between 2000 and 2050.

-1-

Why accept any amount of imprecision? There are situations when a few days matter.

For example, certain benefits are activated on a person¡¯s birthday, such as Social

Security on an individual¡¯s 65th birthday or health insurance coverage for a mammogram

on a woman¡¯s 40th birthday. On a practical level, if each programmer uses a different

method for calculating age, then the analysis results may differ. Using an accurate

method for calculating age ensures that your results are reproducible.

INTEGER AGE ¨C ACCURATE AGE CALCULATION WITH INTCK

The following code calculates integer age so that it always increments age exactly on a

person¡¯s birthday:

FLOOR((INTCK('month',dob,eventdate)-(day(eventdate) ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download