- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to find age using the date of birth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
what is the second date you're comparing to?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.