Calculating Person-Years by Age

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Calculating Person-Years by Age

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,


Accepted Solutions
Solution
a week ago
Super User
Posts: 13,930

Re: Calculating Person-Years by Age


@RW9 wrote:

As @draycut 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


All Replies
PROC Star
Posts: 1,400

Re: Calculating Person-Years by Age

Posted in reply to sas_learnsups

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

Occasional Contributor
Posts: 18

Re: Calculating Person-Years by Age

Super User
Super User
Posts: 9,840

Re: Calculating Person-Years by Age

Posted in reply to sas_learnsups

As @draycut 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.

Solution
a week ago
Super User
Posts: 13,930

Re: Calculating Person-Years by Age


@RW9 wrote:

As @draycut 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;
Occasional Contributor
Posts: 18

Re: Calculating Person-Years by Age

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.

Super User
Posts: 8,216

Re: Calculating Person-Years by Age

Posted in reply to sas_learnsups

@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

 

Occasional Contributor
Posts: 18

Re: Calculating Person-Years by Age

[ Edited ]

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 

Super User
Posts: 8,216

Re: Calculating Person-Years by Age

Posted in reply to sas_learnsups

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

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 113 views
  • 1 like
  • 5 in conversation