+ Reply to Thread
Results 1 to 8 of 8

Thread: calculating age from birth date!

  1. #1
    Points: 991, Level: 16
    Level completed: 91%, Points required for next Level: 9

    Location
    Pasadena
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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?

    Thanks in advance!!

  2. #2
    IBM Rules
    Points: 13,422, Level: 75
    Level completed: 44%, Points required for next Level: 228
    Awards:
    Activity Award

    Posts
    2,601
    Thanks
    124
    Thanked 381 Times in 369 Posts

    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.
    "Facts are stubborn things, but statistics are more pliable." Mark Twain

  3. #3
    Points: 991, Level: 16
    Level completed: 91%, Points required for next Level: 9

    Location
    Pasadena
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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. #4
    IBM Rules
    Points: 13,422, Level: 75
    Level completed: 44%, Points required for next Level: 228
    Awards:
    Activity Award

    Posts
    2,601
    Thanks
    124
    Thanked 381 Times in 369 Posts

    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.
    "Facts are stubborn things, but statistics are more pliable." Mark Twain

  5. #5
    RotParaTon
    Points: 47,151, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardCommunity AwardMaster TaggerFrequent Poster
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,196
    Thanks
    212
    Thanked 1,641 Times in 1,402 Posts

    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?
    "His programming is malfunctioning. It begins! Get your weapons, he's going to become a killbot!!!" - bryangoodrich

  6. #6
    IBM Rules
    Points: 13,422, Level: 75
    Level completed: 44%, Points required for next Level: 228
    Awards:
    Activity Award

    Posts
    2,601
    Thanks
    124
    Thanked 381 Times in 369 Posts

    Re: calculating age from birth date!

    See below. It is how you do what Dason suggests
    "Facts are stubborn things, but statistics are more pliable." Mark Twain

  7. #7
    IBM Rules
    Points: 13,422, Level: 75
    Level completed: 44%, Points required for next Level: 228
    Awards:
    Activity Award

    Posts
    2,601
    Thanks
    124
    Thanked 381 Times in 369 Posts

    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;
    "Facts are stubborn things, but statistics are more pliable." Mark Twain

  8. #8
    Points: 991, Level: 16
    Level completed: 91%, Points required for next Level: 9

    Location
    Pasadena
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: calculating age from birth date!


    Thank you Noetsi and Dason!!

+ Reply to Thread

Posting Permissions

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








Advertise on Talk Stats