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

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
Tom
Super User Tom
Super User

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
;

View solution in original post

8 REPLIES 8
ballardw
Super User

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.

 

 

Merdock
Quartz | Level 8

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!

 

ballardw
Super User

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.

Merdock
Quartz | Level 8
thank you!
Tom
Super User Tom
Super User

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
;
Merdock
Quartz | Level 8
Thank you, Tom, that works!
PaigeMiller
Diamond | Level 26

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
Ksharp
Super User
data _null_;
month=yrdif('01Oct2007'd,'15Nov2011'd,'age')*12;
put month=;
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 8 replies
  • 896 views
  • 5 likes
  • 5 in conversation