Published on :
Reporting INTERNAL_CREATION

Descriptive Analysis and BMI Charts

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating the 'bmi' table via a DATA step with embedded data (datalines), containing an identifier, sex, and BMI category for 20 individuals. Then, it uses the SGPLOT procedure to generate a vertical bar chart of BMI categories, with data labels displayed on each bar. Finally, the GCHART procedure is used to produce a horizontal bar chart for the same variable, providing an alternative view of frequencies.
Data Analysis

Type : INTERNAL_CREATION


The data is created and stored in the 'bmi' table of the WORK library using a DATA step and the DATALINES statement.

1 Code Block
DATA STEP Data
Explanation :
This block creates a temporary dataset named 'bmi'. It reads three variables (id, sex, bmi) from data included directly in the code via 'datalines'. The '&' modifier after 'bmi' allows reading character strings containing spaces.
Copied!
1DATA bmi;
2 INPUT id $ sex $ bmi & $23.;
3 DATALINES;
4 001 Female Not Overweight or Obese
5 002 Male Not Overweight or Obese
6 003 Female Underweight
7 004 Female Not Overweight or Obese
8 005 Female Overweight
9 006 Female Overweight
10 007 Female Not Overweight or Obese
11 008 Male Not Overweight or Obese
12 009 Male Not Overweight or Obese
13 010 Male Overweight
14 011 Female Not Overweight or Obese
15 012 Female Not Overweight or Obese
16 013 Female Not Overweight or Obese
17 014 Female Obese
18 015 Male Overweight
19 016 Female Overweight
20 017 Male Obese
21 018 Female .
22 019 Male Not Overweight or Obese
23 020 Female Obese
24RUN;
2 Code Block
PROC SGPLOT
Explanation :
This block uses the SGPLOT procedure to create a vertical bar chart (vbar) for the 'bmi' variable. The '/ datalabel' option displays the frequency above each bar.
Copied!
1 
2PROC SGPLOT
3DATA = bmi;
4vbar bmi / datalabel;
5RUN;
6 
3 Code Block
PROC GCHART
Explanation :
This block uses the GCHART procedure to create a horizontal bar chart (hbar) for the 'bmi' variable. This older procedure also generates a table of frequency statistics next to the chart.
Copied!
1PROC GCHART DATA = bmi;
2 hbar bmi;
3RUN;
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.