I have a DOB variable as follows and I want to compute age from this variable
DOB
16JUL51:00:00:00
24NOV33:00:00:00
07MAY45:00:00:00
I think INTCK can not be used in this case.
I tried
age = '24AUG16:00:00:00'd-DOB; but its giving me some wierd numbers.
Experts I need your help !
Please refer to this post.
Only difference in your question is date has time part, so apply datepart function on DOB column.
https://communities.sas.com/t5/SAS-Procedures/Age-from-BirthDate/td-p/80935
Both your values are datetime values, which means they are stored as numbers containing the seconds from 01jan1960:00:00:00.
If you subtract them, you once again get a count of seconds, but one that can't be displayed with SAS datetime formats, as it would fall into the first century AD, where the Gregorian calendar doesn't work.
If you use date values (date() and datepart(DOB)), you will get a count of days; to get years, use the intck() function with the correct parameters.
data have;
input DOB:datetime20.;
format DOB datetime19.;
cards;
16JUL51:00:00:00
24NOV33:00:00:00
07MAY45:00:00:00
;
run;
data want;
set have;
age = intck('year',datepart(DOB),date());
run;
proc print noobs;
run;
Result:
DOB age 16JUL1951:00:00:00 65 24NOV1933:00:00:00 83 07MAY1945:00:00:00 71
The third parameter would be better. age = intck('year',datepart(DOB),date(),'c');
Actually I am thinking no need for DATEPART() at all:
age=intck('dtyear',dob,datetime(),'c');
There are native intervals built for datetime values.
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.