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!
data bmi;
input id $ sex $ bmi & $23.;
datalines;
001 Female Not Overweight or Obese
002 Male Not Overweight or Obese
003 Female Underweight
004 Female Not Overweight or Obese
005 Female Overweight
006 Female Overweight
007 Female Not Overweight or Obese
008 Male Not Overweight or Obese
009 Male Not Overweight or Obese
010 Male Overweight
011 Female Not Overweight or Obese
012 Female Not Overweight or Obese
013 Female Not Overweight or Obese
014 Female Obese
015 Male Overweight
016 Female Overweight
017 Male Obese
018 Female .
019 Male Not Overweight or Obese
020 Female Obese
run;
1
DATA 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
24
RUN;
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!
proc sgplot data = bmi;
vbar bmi / datalabel;
run;
1
2
PROC SGPLOT
3
DATA = bmi;
4
vbar bmi / datalabel;
5
RUN;
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!
proc gchart data = bmi;
hbar bmi;
run;
1
PROC GCHARTDATA = bmi;
2
hbar bmi;
3
RUN;
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.