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

Hi All, I'm attempting to calculate age at Event (1st vaccination) for a data set I'm using. I've used this forum to find several different ways to calculate age at event, however, they all result in different values. I'm hoping to find out which of these calculations represents the true age at vaccination for this population.

 

A few details- I calculated participants age at the start of the study ( 12-1-2016), which gave me an age range of 7-21 yrs ( Agetest). I'm using version 9.4.

 

I want to exclude anyone who received a vaccination before age 9. Now, when I attempt to calculate participants' age at first vaccination ( Event), I get different values for how many are actually <9 at the event. With the coding below I get participants age at event as between 0-21. I'm assuming that some clinics erroneously listed the participant's dob and vaccination date as the same. What am I missing about this code that would explain these differences and which code reflects an accurate count at each age?

 

 

Here's the code I've used thus far;

 

data want; set have; today=MDY(12,01,2016);

days=today-BIRTH_DATE;

AGEtest= floor ((intck('month',BIRTH_DATE,today) - (day(today) < day(BIRTH_DATE))) / 12);*age at study start;

 

AgeatVacc=INTCK ('YEAR', BIRTH_DATE, CHVaccDate_1);run;

 

AgeVtest=floor ((intck('month',BIRTH_DATE,CHVaccDate_1) - (day(CHVaccDate_1) < day(BIRTH_DATE))) / 12); *age at first vacc date;

 

AgeVtest2=floor ((intck('month',BIRTH_DATE,CHVaccDate_1)) / 12);*looking at diff btw birth date and 1st vacc date- gives different answers;

 

AgeVTest5=floor ((intck('YEAR',BIRTH_DATE, CHVaccDate_1))); RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

After playing around with it, I arrived at this code:

data have;
input CLIENT_ID BIRTH_DATE :mmddyy10. CHVaccDate_1 :mmddyy10.;
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 VAGE;
run;

Run this and see if it meets your expectations.

View solution in original post

21 REPLIES 21
Reeza
Super User
What about INTCK with the AGE option?
LAsasuser79
Fluorite | Level 6

Hi Reeza, 

 

 

Do you mean something like    AgeatEvent = INTCK('year',dob,eventdate,"Age") ? This generates missing values for the data. 

 

 

PGStats
Opal | Level 21

How about going back to basics, i.e. The Manual

 

The continuous method is useful for calculating anniversaries. For example, you can calculate the number of years a couple is married by executing the following program: 

data b;
   WeddingDay='14feb2000'd;
   Today=today();
   YearsMarried=intck('YEAR', WeddingDay, today(), 'C');
   format WeddingDay Today date9.;
run;

proc print data=b;
run;

The results are WeddingDay=14FEB2000, Today=01OCT2012, and YearsMarried=12. 
PG
LAsasuser79
Fluorite | Level 6
This solution doesn't work because each event "wedding" date is different for each participant. This method works for calculating age of participant at study start, which I have used successfully.
Reeza
Super User

@LAsasuser79 wrote:
This solution doesn't work because each event "wedding" date is different for each participant. This method works for calculating age of participant at study start, which I have used successfully.

 

It should work, assuming you used two variables, please explain how it "doesn't work". 

 

 

LAsasuser79
Fluorite | Level 6

HI Reeeza, 

 

 

This code works for calculating age at study start, which is the same start date for all participants. The output gives me the age in years for each participant. 

 

data want; set have;

today=MDY(12,01,2016);

days=today-BIRTH_DATE;

AGEtest= floor ((intck('month',BIRTH_DATE,today) - (day(today) < day(BIRTH_DATE))) / 12);*age at study start;

 

However, what I am trying to calculate is participant's age at first vaccination, which differs for each participant. Therefore, I can't plug in a date rage for the interval to check against in order to count age correctly. 

Kurt_Bremser
Super User

@LAsasuser79 wrote:
This solution doesn't work because each event "wedding" date is different for each participant. This method works for calculating age of participant at study start, which I have used successfully.

It's time to post some example data in a data step. Right now we're fishing in the dark with respect to your data and have to make up things.

LAsasuser79
Fluorite | Level 6

UPDATED with data lines:

 

Kurt, 

 

See below. 

I calculate age at study start (Age Test) and most importantly age at first vaccination(VAGE). The issue I'm running into is age at first vaccination as it gives me an age range of 0-18, which isn't true based on the age of my sample ( 7-21). I've attached the output for the code. 

 

 

data Inas.hpvdata1; set Inas.hpvdata1;

today=MDY(12,01,2016);

days=today-BIRTH_DATE;

AGEtest= floor ((intck('month',BIRTH_DATE,today) - (day(today) < day(BIRTH_DATE))) / 12);*age at study start;

 

VAGE= INTCK('year',BIRTH_DATE,CHVaccDate_1,"Continuous");run; proc freq; table AGEtest VAGE;run;

proc freq; table AGEtest VAGE;run; 

 

input CLIENT_ID BIRTH_DATE  ddmmyy10. CHVaccDate_1 mmddyy10.;

data lines; 

1, 08212000, 04062009

2,02232002,  04082011

3,05101999, 11222010

4,10191999, 03052012

Kurt_Bremser
Super User

Quote from myself:

"post some example data in a data step".

Don't expect us to type data from pictures.

And I only risked to open your Word document because I have LibreOffice at hand, which reduces the risk of malware somewhat. Many of the people here won't be able to access a docx because their firewalls block Office files.

LAsasuser79
Fluorite | Level 6

Noted. I've updated the post with a few data lines. 

Kurt_Bremser
Super User

After playing around with it, I arrived at this code:

data have;
input CLIENT_ID BIRTH_DATE :mmddyy10. CHVaccDate_1 :mmddyy10.;
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 VAGE;
run;

Run this and see if it meets your expectations.

LAsasuser79
Fluorite | Level 6

I did try this code earlier. My question was related to which of the INTCK code options will give the most accurate age, since they all slightly differed. I am going to use this option with the continuous option as the most valid response. 

Kurt_Bremser
Super User

What are you trying to calculate here:

AGEtest= floor ((intck('month',BIRTH_DATE,today) - (day(today) < day(BIRTH_DATE))) / 12);*age at study start;

There is no variable today in your whole process, so it only yields missing values.

LAsasuser79
Fluorite | Level 6

Here I'm calculating the age of my sample at the start of the study. This code works to do that. I believe my value for today was included in the code I pasted. 

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!

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
  • 884 views
  • 11 likes
  • 6 in conversation