BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Steevo116
Calcite | Level 5

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Angel_Larrion
SAS Employee

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;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Reeza
Super User
Calculate age as if today was birthday and year of birth is Today's year - age (2020 - age).
Compare that value to the actual age to determine year of birth.
Steevo116
Calcite | Level 5

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

 

data want;
        set have;
        Birthday = cat(MOB,DOB);
        new=input(Birthday, 4.0); drop Birthday; rename new=Birthday;
        today = DATE();
        /*Insert statement to convert today MMDD (simple numeric format like Birthday above)*/
        if today >= Birthday then do;
                YOB=/*Format to insert current year*/ - age;
        end;
        if today < Birthday then do;
                YOB=/*Format to insert current year*/ - (age-1);
        end;
run;
Angel_Larrion
SAS Employee

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1677 views
  • 1 like
  • 4 in conversation