Terah
Terah

Reputation: 57

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

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?

Upvotes: 3

Views: 2193

Answers (2)

mjsqu
mjsqu

Reputation: 5452

Use the MDY function and make up values for month and day, e.g.:

date_yrdob = mdy(1,1,yrdob);

Which sets date_yrdob to 1st January of whichever year is represented in yrdob.

Upvotes: 5

Joe
Joe

Reputation: 63434

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');

Upvotes: 5

Related Questions