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-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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