Contributor
Posts: 61

# date of birth and age

Hi,

I want to get age out of the date of birth (DOB) as given below.  I have following questions/points:

1. How can I get today's date in SAS dataset?

2. How can I get age in years, weeks and days?

3. How can I round off if it comes in decimals?

Thanks

 DOB age 12/22/1994 12/5/1990 12/21/1978 12/27/1977 11/28/1980 4/26/1987 6/5/1977 10/8/1980 3/23/1990 8/3/1991 06/01/198 8/26/1982 5/17/1990 10/28/1985 8/8/1981 5/26/1995
Occasional Contributor
Posts: 12

## Re: date of birth and age

Hi,

INTCK() function will not give values in decimals.

data test;
input dob mmddyy10.;
format dob mmddyy10.;
cards;
12/22/1994
12/05/1990
12/21/1978
12/27/1977
;
run;

data test1;
set test;
format date mmddyy10.;
date=today(); /*Get today's date*/
agey=intck('year',dob,date); /*Get age in years*/
agem=intck('month',dob,date); /*Get age in months*/
agew=intck('week',dob,date); /*Get age in weeks*/
aged=intck('days',dob,date); /*Get age in days*/
run;

Contributor
Posts: 61

## Re: date of birth and age

Hi,

Thanks.  My response is similar to what I wrote to Jag; I have already entered data, how can I get my required output by writing codes instead of entering data.

Also, INTCK() will not give decimals but I have seen that even the value is 0.9758 it would give 0 years; is that not wrong?

Contributor
Posts: 20

## Re: date of birth and age

The first subject won't be 22 years old until 12/22/16 but the program results in an age of 22 now even though the subject is only 21.

The yrdif function can be used to correctly calculate age in years in 9.3 and 9.4 but that won't work for months or weeks.

One can read about Billy Kreuter's classic solution to the age calcualtion problem here:

http://www.pauldickman.com/teaching/sas/age.php

http://staff.washington.edu/billyk/TechTips_SC4Q98.pdf

Billy's code can be modified to get age in months or weeks.

Paul

Posts: 1,147

## Re: date of birth and age

we have today() to get today date, the belwo code give the age in years

``````data have;
input DOB: mmddyy10.;
age=yrdif(dob,today(),'age');
format dob date9.;
cards;
12/22/1994
12/5/1990
12/21/1978
12/27/1977
11/28/1980
4/26/1987
6/5/1977
10/8/1980
3/23/1990
8/3/1991
06/01/1988
8/26/1982
5/17/1990
10/28/1985
8/8/1981
5/26/1995
;
``````
Thanks,
Jag
Contributor
Posts: 61

## Re: date of birth and age

Thanks.

My data are already entered and it is a dataset with around a thousand rows.  Is there any way I do not have to enter the rahter I could get the required outcome by using the codes.

Occasional Contributor
Posts: 12

## Re: date of birth and age

Use set statement for your created dataset.

data test1;
set test;
format date mmddyy10.;
date=today(); /*Get today's date*/
agey=intck('year',dob,date); /*Get age in years*/
agem=intck('month',dob,date); /*Get age in months*/
agew=intck('week',dob,date); /*Get age in weeks*/
aged=intck('days',dob,date); /*Get age in days*/
run;

Contributor
Posts: 61

## Re: date of birth and age

Many thanks.

My date is already in this format (mmddyy10), still I need to keep this code?

Occasional Contributor
Posts: 12

## Re: date of birth and age

No need to use format in your program just use the given function statements.

Occasional Contributor
Posts: 12

## Re: date of birth and age

If you have any decimal values use round(age) or rounde(age) to get integer values.

Contributor
Posts: 61

## Re: date of birth and age

I ran the code and it gives todays date and also creats columns for all categories for age but it does not calculate the age and cells/data are blank or missing.

Occasional Contributor
Posts: 12

## Re: date of birth and age

Occasional Contributor
Posts: 12

## Re: date of birth and age

dob
date
agey
agem
agew
aged
1 12/22/1994 03/11/2016 22 255 1107 7750
2 12/05/1990 03/11/2016 26 303 1318 9228
3 12/21/1978 03/11/2016 38 447 1942 13595
4 12/27/1977 03/11/2016 39 459 1993 13954

I just checked in SAS the above result you will get.
Occasional Contributor
Posts: 12