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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.