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

I'm a first time user of the forum, have only recently returned to SASing, and am trying to get back in the saddle.

 

Using SAS 9.2, I am attempting to compute a Body Roundness Index (BRI) from an anthropometric dataset.   The BRI computation is broken down into three steps:  (1) Calculation of a waist to height ratio (WtHR), which expresses proportionality of waist circumference (waistcir) to stature (stature); (2) Calculation of eccentricity (Ecc), in which body shape is expressed in degrees of departure from an ellipse; and (3) Calculation of the BRI.

 

In order, the code entered is:

 

WtHR=round((waistcir/stature)*100, .1);

 

Ecc=sqrt(1-WtHR/3.14159)**2);

 

BRI=(364.2 - 365.5)*Ecc;

 

Running both Proc Print for screening, I've no problem with computed values for WtHR, but receive "." missing values for Ecc and BRI.

 

The system's objection is "Invalid argument to sqrt".  

 

Is the problem one of syntax, or is it deeper?

 

1 ACCEPTED SOLUTION

Accepted Solutions
GaryHeathcote
Fluorite | Level 6

Thanks to one and all for your most helpful replies.   Am happy to report that -- thanks to community members collective guidance -- I'm now able to compute the BRI expression of body roundness, as follows:

 

WtHR = waistcir/stature;

*WtHR=round((waistcir/stature)*100,.1);
*Comment This produced a waist circumference to stature ratio times 100,
which -- being > 1 -- negated my ability, mathematically, to compute a BRI;

 

Ecc=sqrt(1-(WtHR/3.141592653589793)**2);
*Comment Calculates eccentricity of the vertical ellipse around the body;

 

BRI=364.2-365.5*Ecc;
*Comment BRI is Body Roundness Index. Formula developed by Thomas et al.   A healthy
BRI is generally below 10 on the scale of 1-20, with higher scores indicating a
rounder body;

 

Again, thank you one and all for your help.

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26

What mathematically would be an invalid value to the SQRT function? This isn't really a SAS question, it's a math question. So even if you don't know SAS, but you know math, you should be able to come up with an answer. 

--
Paige Miller
quickbluefish
Barite | Level 11
Is WtHR ever >1? If so, your equation for Ecc is going to generate a negative number, which you can't take the square root of. That said, the way you've written the Ecc equation in your question has unbalanced parentheses (one open, 2 close) so I don't really know if the **2 is where it's supposed to be.
Ksharp
Super User
I think your code was not right.
Ecc=sqrt(1-WtHR/3.14159)**2);
You have unmatched parentheses . left is one but right is two. you should delete one of right.
GaryHeathcote
Fluorite | Level 6
Thank you. In fact, I did eliminate the close parentheses on the right in
my last unsuccessful SAS run. My posting erred in that regard.
Apologies (to all) for that confusion.
ballardw
Super User

Best practice on this forum is any time you get a message in the log that you want to question that you provide the code and the message from the log. Copy the text from the log starting at the first line of the data step or procedure through the last line of all the messages. Then on the forum open a text box on the forum using the </> icon that appears above the main message window and paste the text and paste the text.

As a minimum that removes any question as to the exact code that was submitted.

An example providing what should be a valid value for the WtHr variable, if maybe not biologically plausible shows:

1    data example;
2       Wthr = 1;
3       Ecc=sqrt(1-WtHR/3.14159)**2);
                                   -
                                   388
                                   200
                                   76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

4    run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.EXAMPLE may be incomplete.  When this step was
         stopped there were 0 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.03 seconds

Which clearly shows the code you posted is an error and SAS will not do much of anything in the way of output for ECC or any dependent variables.

 

 

 

 

 

FreelanceReinh
Jade | Level 19

Hello @GaryHeathcote and welcome to the SAS Support Communities!

 


@GaryHeathcote wrote:

WtHR=round((waistcir/stature)*100, .1);

 

Ecc=sqrt(1-WtHR/3.14159)**2);

 

BRI=(364.2 - 365.5)*Ecc;


I agree with the other experts that you should first make sure your formulas are correct before implementing them in code.

 

It is possible that all three of the above formulas are incorrect: Comparing them to the similar three-step approach presented in the Wikipedia article Body roundness index,

  1. your factor 100 in the first formula would make sense if waistcir was measured in meters and stature in centimeters. But is this really the case (and not vice versa)? If not, this would most likely cause the "Invalid argument to sqrt" problem (because then WtHR [which Wikipedia denotes WHtR] would tend to be way too large). The rounding unit .1 should be checked, too: Rounding WHtR to tenths in the numeric example shown in the Wikipedia article would change the result quite significantly (from 2.47 to 3.36), which is probably not desirable.
  2. In the second formula the opening parenthesis after the minus sign is missing (as others have mentioned already).
  3. The parentheses in the third formula are definitely wrong and must be removed. (As posted, the BRI would always be negative and the formula could obviously be simplified.)
quickbluefish
Barite | Level 11

It's possible the correct formula for Ecc just involves squaring the inner part (thus guaranteeing a positive number) before taking the square root, in other words, the just taking the absolute value, though not sure it wouldn't just be written with absolute value notation if that were the case.  Like this (line breaks and spaces added for emphasis):

Ecc=sqrt(
   ( 1-WtHR/3.14159 )**2
   );
FreelanceReinh
Jade | Level 19

@quickbluefish wrote:

It's possible the correct formula for Ecc just involves squaring the inner part (thus guaranteeing a positive number) before taking the square root, in other words, the just taking the absolute value, though not sure it wouldn't just be written with absolute value notation if that were the case. 


This would be "possible" (albeit unusual) if we knew nothing about the context of the formula. But the corresponding formula in the Wikipedia article and its explanation clearly show that an opening parenthesis must be inserted after the minus sign:

Ecc=sqrt(1-(WtHR/3.14159)**2);

Only this correction fits the definition of the eccentricity of an ellipse in geometry: see the first table in Wikipedia article Eccentricity (mathematics).

GaryHeathcote
Fluorite | Level 6

Thanks to one and all for your most helpful replies.   Am happy to report that -- thanks to community members collective guidance -- I'm now able to compute the BRI expression of body roundness, as follows:

 

WtHR = waistcir/stature;

*WtHR=round((waistcir/stature)*100,.1);
*Comment This produced a waist circumference to stature ratio times 100,
which -- being > 1 -- negated my ability, mathematically, to compute a BRI;

 

Ecc=sqrt(1-(WtHR/3.141592653589793)**2);
*Comment Calculates eccentricity of the vertical ellipse around the body;

 

BRI=364.2-365.5*Ecc;
*Comment BRI is Body Roundness Index. Formula developed by Thomas et al.   A healthy
BRI is generally below 10 on the scale of 1-20, with higher scores indicating a
rounder body;

 

Again, thank you one and all for your help.

ballardw
Super User

Something that you may find useful: The CONSTANT function. Instead of typing out many digits you can use the CONSTANT('PI') and not have to worry about typo's. Also this function tells someone reading the code what you are using.

There are other constants such as E and Euler's constant plus somewhat system dependent values BIG and SMALL plus log and square root of the BIG and SMALL.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 2767 views
  • 3 likes
  • 6 in conversation