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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

 

2017 - birth_year1 as age,

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Kalai2008
Pyrite | Level 9

Input Data :

Acct            birth_year1

201003       1952

201003        1952

12365          1968

23568          1965

 

Thank you!

Reeza
Super User

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.

Kalai2008
Pyrite | Level 9

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.

Reeza
Super User

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. 

 

 

Reeza
Super User

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

 

 

Kalai2008
Pyrite | Level 9

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

Astounding
PROC Star

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

 

2017 - birth_year1 as age,

Kalai2008
Pyrite | Level 9
Thank you..It worked

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
  • 9 replies
  • 1407 views
  • 0 likes
  • 4 in conversation