BookmarkSubscribeRSS Feed
Polina_UH
Obsidian | Level 7

Dear all,

 

I am trying to calculate BMI SDS values based on child's age and for some reason my code makes calculations only for 5 cases and leaves the other values missing. I am using this formula to calculate BMI SDS: ((BMI / muBMI) ^ nuBMI – 1) / (nuBMI × sigmaBMI). Only the value of BMI is a real variable, all others are constants according to the child's age. I am completely lost at what is wrong with my code. 

 

Here is the code:

 

data boys; set boys;
if age_2_years=. then bmi_s_2=.;
else if age_2_years=2.0 then bmi_s_2=((bmi_2/16.260543289863)**-1.636849607433-1)/(-1.636849607433*0.071322824579);
else if age_2_years=2.01 then bmi_s_2=((bmi_2/16.25885052)**-1.638405877-1)/(-1.638405877*0.071333903);
else if age_2_years=2.02 then bmi_s_2=((bmi_2/16.25714931)**-1.63996991-1)/(-1.63996991*0.071345038 );
else if age_2_years=2.03 then bmi_s_2=((bmi_2/16.25543967)**-1.641541704-1)/(-1.641541704*0.07135623); and so on.... run;

 

As a result I have only 5 values calculated for the age of 2.0 (and I have seven children in my dataset with the age of 2.0).

 

I would greatly appreciate any advice.

 

many thanks in advance!

2 REPLIES 2
Rick_SAS
SAS Super FREQ

Sample data would be useful.

 

I don't know know how the age_2_years variable is computed, but because of numerical precision, it might not be exactly 2.0 or 2.01, etc. You can use the ROUND function to ensure that the value is rounded:
data boys; set boys;
age_2_years = round(age_2_years, 0.01);

if age_2_years=. then bmi_s_2=.;

etc

run;

Patrick
Opal | Level 21

What should happen if the internal value of age_2_years is something like 2.0100001? 

In your current logic you might need to round() your values first or then write logic that checks for ranges like:  2.01<=age_2_years<2.02

 

I don't understand your formula but I would assume you could also use functions to calculate the values you pass in hard coded ...and if that works then you could potentially do this calculation in a single line of code.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 395 views
  • 0 likes
  • 3 in conversation