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

I have 2 variables as below. One is age and other is current date(reporting_date). I need to calculate year of birth from this 2 variables. How do i achieve this?

Age     current_date

53       2018-03-22
53       2018-03-22
51       2018-02-16
54      2018-02-06
55      2018-04-12
60      2018-03-13
62      2018-03-15
71      2018-02-27
71      2018-04-09
56      2018-06-21
56      2018-03-12
67      2018-01-25

 

Many thanks in advance,

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@RW9 wrote:

As @PeterClemmensen has said you can't, accurately.  You can however ascertain year:

dob_year=year(current_date)-age;

And you could also say it is a month of month(current_date) or less.

That is as far as you could say.


And if your current_date is not an actual SAS date value with a SAS date format applied you need to convert that to a date value such as

dob_year=year( input(current_date, yymmdd10.))-age;

View solution in original post

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

You cant. There is not enough information to calculate a date of birth.

sas_learnsups
Obsidian | Level 7

RW9
Diamond | Level 26 RW9
Diamond | Level 26

As @PeterClemmensen has said you can't, accurately.  You can however ascertain year:

dob_year=year(current_date)-age;

And you could also say it is a month of month(current_date) or less.

That is as far as you could say.

ballardw
Super User

@RW9 wrote:

As @PeterClemmensen has said you can't, accurately.  You can however ascertain year:

dob_year=year(current_date)-age;

And you could also say it is a month of month(current_date) or less.

That is as far as you could say.


And if your current_date is not an actual SAS date value with a SAS date format applied you need to convert that to a date value such as

dob_year=year( input(current_date, yymmdd10.))-age;
sas_learnsups
Obsidian | Level 7

Dear RW9, 

That's exactly what I did. I agree with draycut, we cannot calculate date of birth, I actually was looking to derive "Year of Birth"

Thank you for suggesting that.

art297
Opal | Level 21

@sas_learnsups: You marked this as solved, but I question whether you actually have a solution. Unless I missed it, what does current_date represent?

 

Art, CEO, AnalystFinder.com

 

sas_learnsups
Obsidian | Level 7

Hi Art297,

 

Yes i got the solution.

 

I have age and current_date (date of reporting an incident and the persons age on that particular day).

 

I have uploaded screenshot for your reference. 

 

i get the year of birth by following statement:

dob_year=year(current_date)-age;

 

Hope this answers your question!

 

Capture_08_august_2018.PNG 

art297
Opal | Level 21

Just wanted to point out that if there is NO relationship between current_date and age then your dob_year calculation will be off by 1 for half of your data. As an example, run and examine the results of the following:

data test;
  informat dob current_date date9.;
  format dob current_date date9.;
  input age dob current_date;
  calc_age=floor(yrdif(dob,current_date));
  act_dob_year=year(current_date)-calc_age;
  dob_year=year(current_date)-age;  cards;
35 1jan1961 5oct1996
35 1feb1961 5oct1996
35 1mar1961 5oct1996
35 1apr1961 5oct1996
35 1may1961 5oct1996
35 1jun1961 5oct1996
35 1jul1961 5oct1996
35 1aug1961 5oct1996
35 1sep1961 5oct1996
35 1oct1961 5oct1996
35 1nov1961 5oct1996
35 1dec1961 5oct1996
35 1jan1962 5oct1996
35 1feb1962 5oct1996
35 1mar1962 5oct1996
35 1apr1962 5oct1996
35 1may1962 5oct1996
35 1jun1962 5oct1996
35 1jul1962 5oct1996
35 1aug1962 5oct1996
35 1sep1962 5oct1996
35 1oct1962 5oct1996
35 1nov1962 5oct1996
35 1dec1962 5oct1996
53 1jan1964 22mar2018
53 1feb1964 22mar2018
53 1mar1964 22mar2018
53 1apr1964 22mar2018
53 1may1964 22mar2018
53 1jun1964 22mar2018
53 1jul1964 22mar2018
53 1aug1964 22mar2018
53 1sep1964 22mar2018
53 1oct1964 22mar2018
53 1nov1964 22mar2018
53 1dec1964 22mar2018
53 1jan1965 22mar2018
53 1feb1965 22mar2018
53 1mar1965 22mar2018
53 1apr1965 22mar2018
53 1may1965 22mar2018
53 1jun1965 22mar2018
53 1jul1965 22mar2018
53 1aug1965 22mar2018
53 1sep1965 22mar2018
53 1oct1965 22mar2018
53 1nov1965 22mar2018
53 1dec1965 22mar2018
;

Art, CEO, AnalystFinder.com

 

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!

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
  • 8 replies
  • 1658 views
  • 3 likes
  • 5 in conversation