BookmarkSubscribeRSS Feed
Anita_n
Pyrite | Level 9

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

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
andreas_lds
Jade | Level 19

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
Anita_n
Pyrite | Level 9
Thanks to you all for the reply. I now understand the principle behind it

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1706 views
  • 2 likes
  • 4 in conversation