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));
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
;
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.
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!
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.
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
;
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.
data _null_;
month=yrdif('01Oct2007'd,'15Nov2011'd,'age')*12;
put month=;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.