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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 591 views
  • 0 likes
  • 4 in conversation