Hi ,
I need to calculate age at graduation. I was wondering if any of the two methods below are appropriate and take care leap years as well.
Method 1: Age= INTCK('year',dob,graduationdate,"C")
Method 2: Age= (graduationdate-dob)/365.25
Thank you very much
Isn't it a bit strange that one would have to resort to datestring formatting to calculate an age? The matter depends on a specific case: if you are born on the 29th of February (in a leap year, obviously), do you celebrate your birthday on the 28th of February or on the first of March, during non-leap years? If your answer is the former then your age is
intck("year", dob, event, "continuous") /* birthday on the 28th during non-leap years */
otherwise, your age is
intck('year', dob, event) - (put(dob, mmddyy4.) > put(event, mmddyy4.)) /* birthday on March 1st during non-leap years */
Another option is to use function INT(YRDIF(dob, event, "AGE")). It considers that you will celebrate your birthday on the 28th, even on leap years.
The recommended formula:
age = intck('year',dob,event) - (put(dob,mmddyy4.) > put(event,mmddyy4.)) ;
Isn't it a bit strange that one would have to resort to datestring formatting to calculate an age? The matter depends on a specific case: if you are born on the 29th of February (in a leap year, obviously), do you celebrate your birthday on the 28th of February or on the first of March, during non-leap years? If your answer is the former then your age is
intck("year", dob, event, "continuous") /* birthday on the 28th during non-leap years */
otherwise, your age is
intck('year', dob, event) - (put(dob, mmddyy4.) > put(event, mmddyy4.)) /* birthday on March 1st during non-leap years */
Another option is to use function INT(YRDIF(dob, event, "AGE")). It considers that you will celebrate your birthday on the 28th, even on leap years.
This makes a lot sense.Thanks a lot!
Great! Thank you very much
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.