Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAS calculate age based on year of birth and a complete end date

Tags:

numeric

sas

I have a data set that only gives year of birth. I want to calculate age based on when an individual was diagnosed with diabetes. For example I have a diagnosis date of 31Jan2002 and a year of birth 1964. The yrdob variable is NOT a date variable - it is only numeric and every time I try to make it a date variable so I can use the yrdif function it makes all of the years 1965 instead of recognizing the yrdob as a year, not the number of days after 1960.

Therefore my question is:

How do I take a numeric variable that is meant to be interpreted at face value (1965 means the year 1965 - not one thousand sixty-five) and make it a date variable so I can use the yrdif function to calculate age?

like image 765
Terah Avatar asked Nov 24 '25 15:11

Terah


1 Answers

The MDY function will make a date from numerics. So for example,

datevar = mdy(1,1,yearvar);

will make a date variable for Jan 1, (year). (That's the default when only year is known).

So to get age difference, you can use

age=yrdif(diagdate,mdy(1,1,yearvar),'AGE');
like image 150
Joe Avatar answered Nov 27 '25 18:11

Joe