Hello
I am using Base SAS 9.3.
I have a database of patient data including birthdate and admit date to hospital. The database does not have age so I need to derive it from these two fields.
Currently I have:
age_days=intck("days",bdate,admdate);
age_years=floor(age_days/365);
But there are still cases showing up incorrectly. For instance a patient with a birthdate of February 2, 1929 and and admit date of January 19, 2011. The calculation shows as 82 but in fact the patient is just shy of their 82nd birthday so I need it to calculate as 81.
Any suggestions? Thanks very much.
Use the YRDIF function :
age=yrdif(bdate, admdate, 'AGE');
PG
Below is a age calculation we recieved from SAS years ago and I think it will do what you want.
*Age Calculation Macro from SAS;
%macro CalcAge(agevar,bday,as_of);
&AgeVar=int(intck('month',&bday,&as_of)/12);
if month(&bday)=month(&as_of) then
&AgeVar=&AgeVar-(day(&bday)>day(&as_of));
%mend CalcAge;
Hope it helps!
Eric
Hi
This is an amazing group: 2 responses in minutes! Thank you so much.
I've searched on this query before but after posting I did so again and found a blurb by William Kreuter from the Univ of Washington. Eric, I think what you provided is something similar to what he has though I didn't put in a macro:
age_years=floor((intck('month',bdate,admdate)-(day(admdate)<day(bdate))/12);
However I found with this result that it was incorrectly counting when the patient was admitted on their birthday i.e. rounding up for that case.
PG, your result worked though I just had to round it to zero to get what I needed. Thank you both again for such speedy and helpful results!!
I think that Billy's macro does better than yrdif. See
http://support.sas.com/publishing/authors/extras/61860_update.pdf
I'm not sure what you mean by "rounding up for that case." On my birthday, I am one year older than I was a day before my birthday. CMS also determines eligibility as being on the 65th birthday (not the day after).
Doc Muhlbaier
Duke
That paper does not cover "AGE" as the third parameter. In fact, "AGE" was added to fix the problem.
PG
YRDIF with AGE does not get the same value as conventional calculations.Try it for these examples. It counts 29FEB birthdays on 28FEB instead of on 01MAR in non leap years. It seems to grant New Year's babies a birthday on New Year's Eve.
Note that you can test if the event date is before the month and day of birth by comparing the strings produced by the MMDDYY4. format.
data age;
input (dob event ) (:date.) expected ;
format dob event mmddyy10.;
age1 = int(yrdif(dob,event,'age'));
age2 = intck('year',dob,event) - (put(dob,mmddyy4.) > put(event,mmddyy4.)) ;
put (_all_) (=);
cards;
29FEB1960 27FEB1965 4
29FEB1960 28FEB1965 4
29FEB1960 01MAR1965 5
29MAR1960 28JAN1965 4
29MAR1960 29MAR1965 5
29MAR1960 30MAR1965 5
01JAN1960 31DEC1963 3
01JAN1960 01JAN1964 4
01JAN1960 02JAN1964 4
run;
dob=02/29/1960 event=02/27/1965 expected=4 age1=4 age2=4
dob=02/29/1960 event=02/28/1965 expected=4 age1=5 age2=4
dob=02/29/1960 event=03/01/1965 expected=5 age1=5 age2=5
dob=03/29/1960 event=01/28/1965 expected=4 age1=4 age2=4
dob=03/29/1960 event=03/29/1965 expected=5 age1=5 age2=5
dob=03/29/1960 event=03/30/1965 expected=5 age1=5 age2=5
dob=01/01/1960 event=12/31/1963 expected=3 age1=4 age2=3
dob=01/01/1960 event=01/01/1964 expected=4 age1=4 age2=4
dob=01/01/1960 event=01/02/1964 expected=4 age1=4 age2=4
I must bow to this demonstration and vow never to use this function again! Thanks Tom.
PG
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.