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,
@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;
You cant. There is not enough information to calculate a date of birth.
Dear draycut,
I know there is not enough information to calculate date of birth. I was looking if i could derive at least calculate "Year of Birth" which i did.
Thank you very much.
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.
@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;
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.
@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
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!
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.