Quartz | Level 8

## Age in months to the nearest day

Does anybody know how I can obtain age in months, to the nearest day? I'm trying to use a CDC SAS program meant to calculate BMI z-scores and percentile and in the instructions it says that in order to use the program, my data needs to contain the child's age in months (number of months to the nearest day based on the dates of birth and examination).

For example, if a child was born on Oct 1, 2007 and was examined on Nov 15, 2011, the child’s age would be 1506 days or 49.48 months.

I've been using the following syntax but it's giving me an exact number of months, i.e. 49 months, not 49.48?

``intck('month', birthdt, examdt)-(day(examdt)<day(birthdt));``
1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Age in months to the nearest day

The categories in that code only need age in months measured to the half a month.

You can decide what that means.

Here is code that says if it is 15 or more extra days then it is an extra half a month.

Use the Continuous option of INTCK() to calculate the months.  Then you can use the same option of INTNX() to count how many extra days.

``````data have;
input (birthdt examdt) (:date9.);
months = intck('month', birthdt, examdt,'c');
day = examdt - intnx('month',birthdt,months,'same');
agemos = months +0.5*(day>=15);
format birthdt examdt date9.;
cards;
05OCT2007 07NOV2011
05OCT2007 20NOV2011
05OCT2007 28NOV2011
;``````
8 REPLIES 8
Super User

## Re: Age in months to the nearest day

It may help to provide a link to exactly which CDC BMI related files you are using.
I have dealt with some of those that want effectively a "mid-month" value, not a rounding to a "closest day".

You will also need to explain exactly how you get the 0.48 part of 49.48.

Quartz | Level 8

## Re: Age in months to the nearest day

Oh, yes, sorry about that. I am looking here: https://www.cdc.gov/nccdphp/dnpao/growthcharts/resources/sas.htm

Specifically the part where it says "Instructions for SAS users" for how to use the cdc-source-code.sas program. I have a dataset with heights, weights, gender, date of birth and examination dates for my patients, and was trying to obtain gender-specific BMI-for-height-age percentiles and Z-scores.

Thanks!

Super User

## Re: Age in months to the nearest day

If you look in the CDCref_d.csv, or the data set, you will AGEMOS1 variable ends in .5 except for the first one with 0.

So just add .5 to your Intck result for comparison when using AGEMOS1.

Quartz | Level 8

thank you!
Super User

## Re: Age in months to the nearest day

The categories in that code only need age in months measured to the half a month.

You can decide what that means.

Here is code that says if it is 15 or more extra days then it is an extra half a month.

Use the Continuous option of INTCK() to calculate the months.  Then you can use the same option of INTNX() to count how many extra days.

``````data have;
input (birthdt examdt) (:date9.);
months = intck('month', birthdt, examdt,'c');
day = examdt - intnx('month',birthdt,months,'same');
agemos = months +0.5*(day>=15);
format birthdt examdt date9.;
cards;
05OCT2007 07NOV2011
05OCT2007 20NOV2011
05OCT2007 28NOV2011
;``````
Quartz | Level 8

## Re: Age in months to the nearest day

Thank you, Tom, that works!
Diamond | Level 26

## Re: Age in months to the nearest day

The idea of fractional months only makes sense if you are willing to assume the same number of days per month (which I am not willing to assume in my work). Otherwise, it is, in my opinion, gibberish and the numbers to the right of the decimal are meaningless.

You could come up with an answer of 49 months and 14 days, that makes perfect sense to me.

--
Paige Miller
Super User

## Re: Age in months to the nearest day

``````data _null_;
month=yrdif('01Oct2007'd,'15Nov2011'd,'age')*12;
put month=;
run;``````
Discussion stats
• 8 replies
• 566 views
• 5 likes
• 5 in conversation