## Calculate current age

Solved
Frequent Contributor
Posts: 94

# Calculate current age

Hello All,

Thanks for Checking!

I am trying to calculate the age for each person , but I am getting the same age 52 for all the accounts. Please help

proc sql;
create table test.age
as select acct,
int(yrdif(s.Birth_year1,today())) as Age
from test.data s;
run;

Output:

acct age
123 52
124 52
362 52

Accepted Solutions
Solution
‎07-12-2017 04:09 PM
Super User
Posts: 6,785

## Re: Calculate current age

If that's all the information you have, why not use a simple formula:

2017 - birth_year1 as age,

All Replies
Posts: 3,066

## Re: Calculate current age

I think you have to show us (a portion of) the input data for us to be able to help you.

--
Paige Miller
Frequent Contributor
Posts: 94

## Re: Calculate current age

Input Data :

Acct            birth_year1

201003       1952

201003        1952

12365          1968

23568          1965

Thank you!

Super User
Posts: 23,776

## Re: Calculate current age

[ Edited ]

So, how does one calculate an age from a date and year? What are you expecting as the answer?

FYI - this is a logic issue/problem definition not an actual programming problem.

Frequent Contributor
Posts: 94

## Re: Calculate current age

I need to calculate the age of that person. I already have his birthyear and need to calculate the person's age in separate column.

Super User
Posts: 23,776

## Re: Calculate current age

Whats the formula though? Age is usually calculated based on dates but you don't have dates so you can't calculate an exact age. So how do you want to calculate age?

Is it use a mid year value? Or just pick highest age? Or stand on one foot and throw a dart? I can show you code for all...including the last option.

Super User
Posts: 23,776

## Re: Calculate current age

Is s.birth_year1 a year or a SAS date. If it's a year this wouldn't work because YRDIF expects Dates.

Frequent Contributor
Posts: 94

## Re: Calculate current age

Right ! Birth_year1 -- Its NUM and in BEST12. format.

Solution
‎07-12-2017 04:09 PM
Super User
Posts: 6,785

## Re: Calculate current age

If that's all the information you have, why not use a simple formula:

2017 - birth_year1 as age,

Frequent Contributor
Posts: 94