Thread: calculating age from birth date!

1. calculating age from birth date!

Hi all

I am stuck!! I want to calculate age of a person based on birth date, taking leap year into consideration.

For eg. if birth date is 01/03/1988 then what will be the age on 01/03/2006?

2. Re: calculating age from birth date!

This should work

(floor ((intck('month',
DOB,
DATE()) - (day(DATE()) < day (DOB)))/12) )

DOB is the field when they were born. DATE is the date field you want to check their age at. If you have trouble with this let me know. I have run it many times and the ages always worked out.

3. Re: calculating age from birth date!

Thank you so much Noetsi.

I also had one more question. I want to calculate the date on a persons 13th birthday...based on his/hers birthday! Can someone help me with this please??

4. Re: calculating age from birth date!

That will be very difficult to do. The problem is that depending when you were born you would get diffent number of leap years. So that you can't add a specific number of days to a birthday to see when you will be 13, because what day to add will be different for this reason.

5. Re: calculating age from birth date!

There are fairly standard algorithms to take leap years into account but I would think calculating the date would be easy right? If they were born on DD/MM/YYYY wouldn't the date on their 13th birthday be DD/MM/(YYYY+13). Or are you talking day of the week?

6. Re: calculating age from birth date!

See below. It is how you do what Dason suggests

7. Re: calculating age from birth date!

This works

INTNX("YEAR",t1.Age,13)

Where t1.Age is the birthdate. It will give you 13 years later. Make sure you use a format statement (DATE9. is a good format) or you will end up with a SAS Julian number not a formated day

This is the full code I ran in SQL

PROC SQL;
CREATE TABLE WORK.QUERY_FOR_AGETEST AS
SELECT t1.Age,
/* Calculation */
(INTNX("YEAR",t1.Age,13)) FORMAT=DATE9. AS Calculation
FROM WORK.AGETEST t1;
QUIT;

8. Re: calculating age from birth date!

Thank you Noetsi and Dason!!

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts