Dear all,
am a little bit confused about calculating age from two dates.
I have seen different methods and am not sure which is right.
Is it right to calculate age considering leap years:
(in years this way): intck("year", birthdate, interviewdate)
(in months): intck("month", birthdate, interviewdate)
(in days): intck("day", birthdate, interviewdate)
Is it also right to use: floor((interviewdate-birthdate)/365)
thanks for the help
Dividing by 365 ignores leap years, and in some cases will result in incorrect ages.
INTCK is the better method and does take into account leap years
A correct calculation requires using the fourth parameter of intck, because someone born on 1. April 2011 is still nine years old, not ten (for future readers: today is 03.02.2021 ddmmyy).
69 data _null_; 70 birthday = '01Apr2011'd; 71 today = today(); /*'03Feb2021'd;*/ 72 73 yd = yrdif(birthday, today); 74 d1 = intck('year', birthday, today); 75 d2 = intck('year', birthday, today, 'c'); 76 77 put yd=; 78 put d1=; 79 put d2=; 80 run; yd=9.8438356164 d1=10 d2=9
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.