DATA Step, Macro, Functions and more

Calculate current age

Accepted Solution Solved
Reply
Contributor
Posts: 53
Accepted Solution

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: 5,097

Re: Calculate current age

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

 

2017 - birth_year1 as age,

View solution in original post


All Replies
Trusted Advisor
Posts: 1,631

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.

Contributor
Posts: 53

Re: Calculate current age

Input Data :

Acct            birth_year1

201003       1952

201003        1952

12365          1968

23568          1965

 

Thank you!

Super User
Posts: 17,943

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.

Contributor
Posts: 53

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: 17,943

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: 17,943

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. 

 

 

Contributor
Posts: 53

Re: Calculate current age

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

Solution
‎07-12-2017 04:09 PM
Super User
Posts: 5,097

Re: Calculate current age

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

 

2017 - birth_year1 as age,

Contributor
Posts: 53

Re: Calculate current age

Thank you..It worked
☑ This topic is solved.

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

Discussion stats
  • 9 replies
  • 171 views
  • 0 likes
  • 4 in conversation