BookmarkSubscribeRSS Feed
Sharan
Obsidian | Level 7

I am trying to find age using the date of birth. 

5 REPLIES 5
Reeza
Super User

You need two dates to calculate age, the day of birth and a reference day, for example, Age as of February 1, 2022.

YRDIF() is one method, see the second example here:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/p1pmmr2dtec32an1vbsqmm3abil5.h...

Or an older method:
https://www.pauldickman.com/sastips/age/

 


@Sharan wrote:

I am trying to find age using the date of birth. 


 

Sajid01
Meteorite | Level 14

Hello
Here is an interesting paper that reviews many approaches. Select the one that suits your needs

Your Age In People Years: Not All Formulas Are the Same (pharmasug.org)

And do revie this too 

The YRDIF Function (wordpress.com) 

 

 

tarheel13
Rhodochrosite | Level 12

what is the second date you're comparing to? 

PaigeMiller
Diamond | Level 26

@Sharan wrote:

I am trying to find age using the date of birth. 


Please take a minute and explain how you would do this pencil and paper? What are the exact steps? Once you know that, you (perhaps with our help) can create SAS code to do the same thing.

--
Paige Miller
Sajid01
Meteorite | Level 14

Hello @Sharan 
Further to the references I have cited above, you can use the code which gives the age in years months and days. I have taken 01/01/1960 as the date of birth. Make sure that it serves your purpose.

I would like to emphasize that the references I gave above are a must read if you want a good understanding of the pros and cons of different approaches.

data a;
  input @1 dob mmddyy10.;
  tod=today();            
   years = intck('year', dob, tod, 'c');
   months = intck('month', intnx('year', dob, years, 's'), tod, 'c');
  days = tod - intnx('month', dob, months + years*12, 's');
  put "Age is " years "Years  "  months "Months and "  Days   "Days.";
   format dob tod mmddyy10.;
datalines;
01/01/1960 
;
run;

You can see this in the log for todays date (February 26,2022). 

Age is 62 Years  1 Months and 25 Days.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 2640 views
  • 4 likes
  • 5 in conversation