BookmarkSubscribeRSS Feed
deega
Quartz | Level 8

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 !

 

4 REPLIES 4
RahulG
Barite | Level 11

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

Kurt_Bremser
Super User

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

 

Ksharp
Super User
The third parameter would be better.

age = intck('year',datepart(DOB),date(),'c');

Haikuo
Onyx | Level 15

Actually I am thinking no need for DATEPART() at all:

age=intck('dtyear',dob,datetime(),'c');

There are native intervals built for datetime values.

 

sas-innovate-2024.png

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.

 

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
  • 4 replies
  • 1279 views
  • 2 likes
  • 5 in conversation