BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

Hi,

I have a date(DOB) and I want to know the years?

example:

DOB

12sep1982

I want something like(probably not in decimals)

AGE:

31

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Miracle
Barite | Level 11

You may like to read this -

 

Age Is Just a Number: Accurately Calculating Integer and Continuous Age by Sara Adams and Chris Colby, ICON Clinical Research, San Francisco, CA

 

The paper discusses integer age and continuous age -- and methods to calculate each.

 

And from @Tom:

If have SAS 9.3 or higher use YRDIF(dob,eventdt,'AGE'); [article with examples here]

 

SAS instructor @D_Dunlap covers this topic and many other Date function FAQs in this video.

 

View solution in original post

12 REPLIES 12
Linlin
Lapis Lazuli | Level 10

data have;

format dob date9.;

input dob date9.;

cards;

02sep1982

;

data want;

set have;

age=int((today()-dob)/365.25);

proc print;run;

Scott_Mitchell
Quartz | Level 8

The INTCK function measures the number of intervals between 2 dates.

DATA WANT;

SET HAVE;

AGE = INTCK('YEAR',DOB,TODAY());

RUN;

Patrick
Opal | Level 21

Using INTCK() the following would return '1' which I believe is not what you would expect to get as age:

INTCK('YEAR','31DEC2012'd,'01JAN2013'd);

Scott_Mitchell
Quartz | Level 8

Agreed Patrick.  Once I read your suggestion regarding YRDIF I remembered that INTCK was the incorrect solution for this scenario.

NoClassAllSAS
Calcite | Level 5

I believe this happens because the alignment option in the INTCK function defaults to DISCRETE, which counts interval boundaries in between two dates, rather than CONTINUOUS, which counts full intervals in between dates, shifted to the start date.

 

The following code should work:

 

AGE = INTCK('YEAR',DOB,TODAY(),'C');

 

 

See here for details:

http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p1md4mx2crz...

AZIQ1
Quartz | Level 8
Hi,
When I use the INTCK function I get a message (window is full and must be cleared. Select:
F to file.
P to Print
S to save or
C to clear the window without saving

Any insights why this is happening?
Patrick
Opal | Level 21

age=YRDIF(DoB, today(), 'ACT/ACT') ;

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

Miracle
Barite | Level 11

You may like to read this -

 

Age Is Just a Number: Accurately Calculating Integer and Continuous Age by Sara Adams and Chris Colby, ICON Clinical Research, San Francisco, CA

 

The paper discusses integer age and continuous age -- and methods to calculate each.

 

And from @Tom:

If have SAS 9.3 or higher use YRDIF(dob,eventdt,'AGE'); [article with examples here]

 

SAS instructor @D_Dunlap covers this topic and many other Date function FAQs in this video.

 

AZIQ1
Quartz | Level 8
Hi,
When I use the INTCK fuction I get a message (window is full and must be cleared. Select:
F to file.
P to Print
S to save or
C to clear the window without saving

Any insights why this is happening?
new_sas2015
Calcite | Level 5

I am trying to calculte age as well using SAS 9.4.

 

this is the code i have used but the age is off by one year. How to correct it?

*creating Mat_age*/;
MAT_AGE = (int(new_DOB - new_MomDOB)/365.25);

ChrisHemedinger
Community Manager

I think you intended to apply the INT function to the entire computed value, so you need to move a paren:

 

MAT_AGE = int( (new_DOB - new_MomDOB) /365.25);

But the better way (I think) is to use YRDIF with the AGE modifier:

 

MAT_AGE = yrdif(new_DOB, new_MomDOB,'AGE');

See: http://blogs.sas.com/content/sasdummy/2011/07/12/computing-age-in-sas-9-3/

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 12 replies
  • 62010 views
  • 12 likes
  • 10 in conversation