BookmarkSubscribeRSS Feed
adriannek
Calcite | Level 5

Hi all, 

 

I'm trying to find the birth year for a dataset, but I'm solely provided with the birthday, birth month (numeric), and age. How would I tackle this problem? 

 

Thanks!

4 REPLIES 4
PaigeMiller
Diamond | Level 26
What does "birth year of a dataset" mean? Creation date of the file?
--
Paige Miller
adriannek
Calcite | Level 5

So, I have a dataset that contains customer's birthday, birth month and their age. I'm trying to find the birthday of each customer, which includes their birth year. Any suggestions? 

Tom
Super User Tom
Super User

I sounds like you don't actually have the birthday as that would imply you know the year of birth. 

So let's assume you mean that you just have the month of the year and day of the month. So something like this:

data have;
  input age month day;
cards;
10 11 23
10 11 20 
;

To use AGE to calculate the birthday you need to know the date at which the age was calculated.  So let's assume it is the age as of today.  So to find the year of birth just subtract the age from the year of the date.  And then if the month/day of birth is after this point in the year you need to subtract one.

data want ;
  set have;
  date=today();
  format date date9.;
  year=year(date)-age;
  if date < mdy(month,day,year(date)) then year=year-1;
run;
Obs    age    month    day         date    year

 1      10      11      23    22NOV2020    2009
 2      10      11      20    22NOV2020    2010

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 723 views
  • 0 likes
  • 4 in conversation