Published on :
Reporting SASHELP

Comparative BMI Analysis and Visualization

This code is also available in: Deutsch Español Français
The script is divided into three main parts. First, PROC FCMP is used to create four custom functions: BMI (standard BMI), newBMI (a BMI variant), BMIDiff (the difference between the two BMIs), and absBMIDiff (the absolute value of this difference). These functions are stored in the sasuser.cmplib library. Second, PROC TEMPLATE defines a STATGRAPH template named 'bmi'. This template includes a rangeAttrMap to color the bubbles of the graph based on the BMI difference and a bubblePlot that visualizes height, weight, and the absolute BMI difference. The color of the bubbles indicates whether the new BMI is greater or lesser than the old one. Finally, PROC SGRENDER uses the 'bmi' template with sashelp.class data to generate the graph, thus visualizing the comparison of the two BMI calculation methods for each individual in the dataset.
Data Analysis

Type : SASHELP


The data used for rendering the graph comes from the `sashelp.class` dataset, which is a demonstration dataset integrated into SAS and thus internal to the system.

1 Code Block
PROC FCMP
Explanation :
This block uses `PROC FCMP` to define four custom functions that will be used later. `BMI` calculates the classic Body Mass Index. `newBMI` calculates an alternative version of BMI with a different formula (power 2.5 instead of 2). `BMIDiff` calculates the difference between the new BMI and the old one. Finally, `absBMIDiff` returns the absolute value of this difference. These functions are compiled and stored in the `sasuser.cmplib.test` library for reusability. The `options cmplib=sasuser.cmplib;` statement makes these functions accessible for subsequent steps.
Copied!
1PROC FCMP outlib=sasuser.cmplib.test;
2/* http://people.maths.ox.ac.uk/trefethen/bmi.html */
3 function BMI(height_inch, weight_lb);
4 return (703 * weight_lb / (height_inch ** 2));
5 endsub;
6 function newBMI(height_inch, weight_lb);
7 return (5734 * weight_lb / (height_inch ** 2.5));
8 endsub;
9 function BMIDiff(height_inch, weight_lb);
10 return (newBMI(height_inch, weight_lb)
11 - BMI(height_inch, weight_lb));
12 endsub;
13 function absBMIDiff(height_inch, weight_lb);
14 return(abs(BMIDiff(height_inch, weight_lb)));
15 endsub;
16RUN; QUIT;
17options cmplib=sasuser.cmplib;
2 Code Block
PROC TEMPLATE (STATGRAPH)
Explanation :
This block defines an SG (SGPLOT) graph template named 'bmi' using `PROC TEMPLATE`. It configures a `rangeAttrMap` (`ram1`) to manage bubble coloring: from green to white for negative BMI differences (new BMI < old BMI), and from white to red for positive differences (new BMI > old BMI). The `bmiDiff` variable is dynamically created by evaluating the previously defined `BMIDiff` function. The graph title is defined, and a `bubblePlot` is created where the bubble size is proportional to the absolute BMI difference (`absBMIDiff`), and the color is determined by `bmiDiff` via the `rangeAttrMap`. A continuous legend is added to explain the coloring. A footer indicates the source of the BMI formulas.
Copied!
1PROC TEMPLATE;
2 define statgraph bmi;
3 beginGraph;
4 rangeAttrMap name="ram1";
5 range min - 0 / rangeColorModel=(green white);
6 range 0 - max / rangeColorModel=(white red);
7 endRangeAttrMap;
8 rangeAttrVar var=eval(BMIDiff(height, weight)) attrVar=bmiDiff attrMap="ram1";
9 entryTitle "BMIs for sashelp.class: New vs Old";
10 layout overlay;
11 bubblePlot x=weight y=height size=eval(absBMIDiff(height, weight)) /
12 name="bp1"
13 dataTransparency=0.3
14 colorResponse=bmiDiff
15 ;
16 continuousLegend "bp1" / title='New - Old' vAlign=bottom;
17 endLayout;
18 entryFootnote halign=left "BMI formulae from: http://people.maths.ox.ac.uk/trefethen/bmi.html";
19 endGraph;
20 END;
21RUN;
3 Code Block
PROC SGRENDER
Explanation :
This block uses `PROC SGRENDER` to generate the graph. It specifies that the data comes from the `sashelp.class` dataset and that the graph template to use is 'bmi', defined in the previous `PROC TEMPLATE` block. This step executes the visual creation of the bubble plot, applying the FCMP functions and style rules defined in the template.
Copied!
1 
2PROC SGRENDER
3DATA=sashelp.class template=bmi;
4RUN;
5 
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Reference URL for BMI formulas: http://people.maths.ox.ac.uk/trefethen/bmi.html, cited in the code.