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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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