BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kurt_Bremser
Super User

OK, saw it.

Run this:

data have;
input CLIENT_ID BIRTH_DATE :mmddyy10. CHVaccDate_1 :mmddyy10.;
today=MDY(12,01,2016);
AGEtest= floor ((intck('month',BIRTH_DATE,today) - (day(today) < day(BIRTH_DATE))) / 12);*age at study start;
agetest1 = intck('year',BIRTH_DATE,today,'c');
VAGE = INTCK('year',BIRTH_DATE,CHVaccDate_1,"Continuous");
format BIRTH_DATE CHVaccDate_1 mmddyy10.;
datalines; 
1 08212000 04062009
2 02032002 04082011
3 05101999 11222010
4 10191999 03052012
;
run;

proc freq;
table agetest agetest1 VAGE;
run;

At least for the set of test data, both calculations for agetest resolve to the same value, and vage also looks correct.

LAsasuser79
Fluorite | Level 6
Thank you! I'm going to use the code for VAGE for my calculation.
Astounding
PROC Star

INTCK is tricky, and not a good idea for calculating AGE.  It counts the number of boundaries crossed, not the number of intervals.  For example:

 

age = intck('year', '28dec2016'd, '02jan2017'd);  ==> 1, because 1 instance of January 1st is encountered

 

age = intck('year', '02jan2017'd, '31dec2017'd); ==> 0, because 0 instances of January 1st are encountered

 

You might find it easier to just count days.  For example, an approximate formula would be:

 

if (CHVaccDate_1 - BIRTH_DATE) < (365 * 7) + (366 * 2) then delete;

 

Or you can experiment with a different function:

 

if CHVaccDate_1 < intnx('year', BIRTH_DATE, 9, 'same') then delete;

 

If haven't really tested that last one sufficiently, but there is definitely a combination that would work using INTNX.

PGStats
Opal | Level 21

INTCK("YEAR", d1, d2, "CONTINUOUS") uses d1 as the year boundary, so it does calculate age (in years) appropriately.

PG
Astounding
PROC Star

Excellent!  Time for me to play with my new toy.

 

@PGStats solution works like a charm.  One sample test program:

 

data test;

do d='14feb2016'd to '01mar2016'd;

age = intck('year', '20feb2015'd, d, 'continuous');

output;

end;

run;

 

proc print data=test;

title 'Start = February 20, 2015';

format d date9.;

run;

art297
Opal | Level 21

If you're on at least 9.3, I'd used the yrdif function. e.g.:

age=YRDIF(start-date,end-date);

There is a third parameter you can add, but age is the default for that parameter.

 

Art, CEO, AnalystFinder.com

 

art297
Opal | Level 21

My only problem with INTCK for calculating age is how it deals with the leap year situation, i.e., when one is born on 2/29 of a leap year and you are testing it with 2/28 of a leap year. I agree with YRDIF's definition that it should be one year greater than the INTCK calculation.

e.g.:

 

data have;
  input CLIENT_ID BIRTH_DATE :mmddyy10. CHVaccDate_1 :mmddyy10.;
  intck_AGE = INTCK('year',BIRTH_DATE,CHVaccDate_1,"Continuous");
  yrdif_age=int(YRDIF(BIRTH_DATE,CHVaccDate_1));
  format BIRTH_DATE CHVaccDate_1 mmddyy10.;
  datalines; 
1 08212000 04062009
2 02032002 04082011
3 05101999 11222010
4 10191999 03052012
5 02292012 02282016
6 02292012 02282017
7 02292012 02292016
;
run;

Art, CEO, AnalystFinder.com

 

 

 

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
  • 21 replies
  • 922 views
  • 11 likes
  • 6 in conversation