08-23-2016 10:47 PM
I have a DOB variable as follows and I want to compute age from this variable
I think INTCK can not be used in this case.
age = '24AUG16:00:00:00'd-DOB; but its giving me some wierd numbers.
Experts I need your help !
08-23-2016 11:02 PM
Please refer to this post.
Only difference in your question is date has time part, so apply datepart function on DOB column.
08-24-2016 02:07 AM - edited 08-24-2016 02:09 AM
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;
DOB age 16JUL1951:00:00:00 65 24NOV1933:00:00:00 83 07MAY1945:00:00:00 71
08-24-2016 10:33 AM
Actually I am thinking no need for DATEPART() at all:
There are native intervals built for datetime values.