Hello,
I'm trying to derive a year of birth (YOB) when month of birth (MOB), day of birth (DOB), age and a reference date (TODAY) are all available. For example, with some fictitious data:
YOB -
MOB -10
DOB - 26
AGE- 30
Date data was entered: TODAY = DATE();
Thank you,
Steve
you can use the following code to do that:
data want;
set have;
if mdy(mob,dob,year(today())) - today()<=0 then YOB=year(intnx("year",today(),-age)) ;
else YOB=year(intnx("year",today(),-age-1));
run;
You tell us. If you had to do this pencil and paper rather than in SAS, what is the answer you want from this example? Show the calculation steps.
Thanks Reeza, I've made progress with your help. This is what I have so far, however I'm missing a statement and some formats to automatically add year (program will run on large dataset over more than one year).
There might be a better way to express today's date so I don't need to remove the year afterwards
you can use the following code to do that:
data want;
set have;
if mdy(mob,dob,year(today())) - today()<=0 then YOB=year(intnx("year",today(),-age)) ;
else YOB=year(intnx("year",today(),-age-1));
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.