Jacob Ian
Jacob Ian

Reputation: 699

SAS find date of birth from age

I have a dataset that has VisitDate and AgeAtVisit. I need DateOfBirth.

I know that if I went from VisitDate and DateOfBirth I can calculate AgeAtVisit from AgeAtVisit = intck('year',DateOfBirth,VisitDate);

However I am not sure how to go backwards.

My data is as so:

   ID       VisitDate        AgeAtVisit
    1         01/01/2000        73.25
    2         03//03/2000       74.22
    3         06/06/2006       65.30

How can I go from this to date of birth?

I thought about trying to manually do an equation like

  age = (Date of visit -date of birth)/365.25

but I can't just rearrange because I can't subtract age from date of visit. I can't use YearDiff because I only have one date. I don't think I can use intck. Any suggestions?

Upvotes: 2

Views: 1384

Answers (1)

Joe
Joe

Reputation: 63434

You can absolutely do what you were suggesting. Dates are numbers of days since 1/1/1960, so you can add/subtract days with impunity. You might be off by a day or so across a lifetime, though, given the imperfection of leap years (2000 was a leap year fortunately so unless you have > 116 yo people, you're probably okay).

data have;
input ID       VisitDate  :mmddyy10. AgeAtVisit;
format visitDate date9.;
datalines;
    1         01/01/2000        73.25
    2         03/03/2000       74.22
    3         06/06/2006       65.30
;;;;
run;

data want;
  set have;
  dateOfBirth = visitDate - 365.25*ageAtVisit;
  format dateOfBirth date9.;
run;

If you actually need perfect accuracy, you'd need something better than what you have for AgeAtVisit.

Upvotes: 2

Related Questions