Hi,
I have a date(DOB) and I want to know the years?
example:
DOB
12sep1982
I want something like(probably not in decimals)
AGE:
31
Thanks
You may like to read this -
Age Is Just a Number: Accurately Calculating Integer and Continuous Age by Sara Adams and Chris Colby, ICON Clinical Research, San Francisco, CA
The paper discusses integer age and continuous age -- and methods to calculate each.
And from @Tom:
If have SAS 9.3 or higher use YRDIF(dob,eventdt,'AGE'); [article with examples here]
SAS instructor @D_Dunlap covers this topic and many other Date function FAQs in this video.
data have;
format dob date9.;
input dob date9.;
cards;
02sep1982
;
data want;
set have;
age=int((today()-dob)/365.25);
proc print;run;
The INTCK function measures the number of intervals between 2 dates.
DATA WANT;
SET HAVE;
AGE = INTCK('YEAR',DOB,TODAY());
RUN;
Using INTCK() the following would return '1' which I believe is not what you would expect to get as age:
INTCK('YEAR','31DEC2012'd,'01JAN2013'd);
Agreed Patrick. Once I read your suggestion regarding YRDIF I remembered that INTCK was the incorrect solution for this scenario.
I believe this happens because the alignment option in the INTCK function defaults to DISCRETE, which counts interval boundaries in between two dates, rather than CONTINUOUS, which counts full intervals in between dates, shifted to the start date.
The following code should work:
AGE = INTCK('YEAR',DOB,TODAY(),'C');
See here for details:
age=YRDIF(DoB, today(), 'ACT/ACT') ;
You may like to read this -
Age Is Just a Number: Accurately Calculating Integer and Continuous Age by Sara Adams and Chris Colby, ICON Clinical Research, San Francisco, CA
The paper discusses integer age and continuous age -- and methods to calculate each.
And from @Tom:
If have SAS 9.3 or higher use YRDIF(dob,eventdt,'AGE'); [article with examples here]
SAS instructor @D_Dunlap covers this topic and many other Date function FAQs in this video.
If have SAS 9.3 or higher use YRDIF(dob,eventdt,'AGE');
I am trying to calculte age as well using SAS 9.4.
this is the code i have used but the age is off by one year. How to correct it?
*creating Mat_age*/;
MAT_AGE = (int(new_DOB - new_MomDOB)/365.25);
I think you intended to apply the INT function to the entire computed value, so you need to move a paren:
MAT_AGE = int( (new_DOB - new_MomDOB) /365.25);
But the better way (I think) is to use YRDIF with the AGE modifier:
MAT_AGE = yrdif(new_DOB, new_MomDOB,'AGE');
See: http://blogs.sas.com/content/sasdummy/2011/07/12/computing-age-in-sas-9-3/
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.