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
If that's all the information you have, why not use a simple formula:
2017 - birth_year1 as age,
I think you have to show us (a portion of) the input data for us to be able to help you.
Input Data :
Acct birth_year1
201003 1952
201003 1952
12365 1968
23568 1965
Thank you!
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.
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.
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.
Is s.birth_year1 a year or a SAS date. If it's a year this wouldn't work because YRDIF expects Dates.
Right ! Birth_year1 -- Its NUM and in BEST12. format.
If that's all the information you have, why not use a simple formula:
2017 - birth_year1 as age,
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.