I am looking for a solution to elegantly display age.
Say I have two datetime varoiables: DOB and a variable called School Entry, at which age were the children schooled ?
Time_in_Seconds = (School Entry - DOB) - what is the best way to convert this into age including years, months and days?
Often it is just displayed in years, but I would want a more exact approach, therefore something like : Tane is 12 years, 5 months and 4 days old.
I could create someting over multiple colums, whereby
age_min =ROUND ((age_sec)/60);
age_h =ROUND ((age_sec)/3600);
age_d =ROUND ((age_sec)/86400);
age_y =ROUND ((age_sec)/31536000);
but that is not very elegant. Would anybody know a better way to deal with this?
many thanks
Try the INTCK function. This will adjust properly for issues like leap years, differing number of days in months for example.
years = intck('dtyear', DOB, SchoolEntry, 'C');
months = intck('dtmonth', DOB, SchoolEntry, 'C');
Check out the documentation here:
Try the INTCK function. This will adjust properly for issues like leap years, differing number of days in months for example.
years = intck('dtyear', DOB, SchoolEntry, 'C');
months = intck('dtmonth', DOB, SchoolEntry, 'C');
Check out the documentation here:
Asuming DIF is the difference in seconds then you may try
age = put(datepart(DIF),yymmdd10.);
Find below a sample program that calculates the age in years months and days.
The sample is based on a SAS date value
data ageCalc;
infile cards dlm=",";
input
min_date : date9.
max_date : date9.
;
years = intck('year',min_date,max_date,'c');
months = intck('month',intnx('year',min_date,years,'same'),max_date,'c');
days = intck('day',intnx('month',intnx('year',min_date,years,'same'),months,'same'),max_date,'c');
format min_date max_date ddmmyyp10.;
cards;
10NOV1963,26sep2013
15mar1961,11oct2001
31jan2000,01mar2000
29feb2000,28feb2001
;
proc print data=ageCalc;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.