Published on :
Reporting SASHELP

Health Data Visualization with ODS Graphics

This code is also available in: Deutsch Español Français
The script begins by configuring the ODS environment for generating graphical outputs in LISTING format with high resolution (300 dpi) and a specified output path. It then produces a first graphic (Figure 2.7.1) which is a panel scatter plot. This graph represents the relationship between cholesterol level and systolic blood pressure, segmented by sex and weight status. A second-degree polynomial regression curve is added to each panel to show the trend. The second graphic (Figure 2.7.2) is a panel histogram, displaying the distribution of cholesterol, also segmented by sex and weight status. A density estimation curve is superimposed on the histogram to illustrate the shape of the distribution. Filters are applied to the data to include only individuals over 45 years old and exclude those with 'Underweight' weight status.
Data Analysis

Type : SASHELP


The data used comes from the standard SASHELP.HEART table, which is an example data source provided with SAS. WHERE clauses are applied to filter this data, retaining only records where 'ageatstart' is greater than 45 and 'weight_status' is not 'Underweight'.

1 Code Block
ODS Graphics / PROC SGPANEL
Explanation :
This block initializes the ODS environment by defining macros for the output path (`gpath`) and image resolution (`dpi`). It closes any previous HTML output and opens a LISTING output configured for graphics. Then, it configures ODS GRAPHICS options for generating the first graph. The PROC SGPANEL procedure is used to create a panel scatter plot. The 'sashelp.heart' data is filtered. Panels are defined by 'sex' and 'weight_status'. A scatter plot ('scatter') shows the cholesterol-systolic relationship, and a 2nd-degree polynomial regression line ('reg') is added. Style attributes are applied to the axes and panel headers.
Copied!
1%let gpath='.'; /*--Put your Folder Name here--*/
2%let dpi=300;
3ods html close;
4ods listing gpath=&gpath image_dpi=&dpi;
5 
6/*--Fig 2.7.1 Panel Scatter--*/
7ods graphics / reset attrpriority=color noborder width=4in height=3in imagename='2_7_1_Data_Panel_Scatter';
8title 'Cholesterol by Systolic';
9PROC SGPANEL DATA=sashelp.heart(where=(ageatstart > 45 and weight_status ne 'Underweight')) noautolegend;
10panelby sex weight_status / layout=panel novarname headerattrs=(size=7);
11 scatter x=cholesterol y=systolic / markerattrs=graphdata1(symbol=circlefilled) transparency=0.7;
12 reg x=cholesterol y=systolic / degree=2 nomarkers lineattrs=graphfit;
13 rowaxis valueattrs=(size=7);
14 colaxis valueattrs=(size=7);
15RUN;
16title;
2 Code Block
ODS Graphics / PROC SGPANEL
Explanation :
This block configures ODS GRAPHICS options for the second graph, which is a panel histogram. The PROC SGPANEL procedure is used again with the same filtered data as the previous graph. It displays the distribution of the 'cholesterol' variable using a histogram ('histogram') and superimposes a density estimation curve ('density') for each panel. Panels are also segmented by 'sex' and 'weight_status'. Font size adjustments are made for axis values and labels.
Copied!
1/*--Fig 2.7.2 Panel Histogram--*/
2ods graphics / reset attrpriority=color noborder width=4in height=3in imagename='2_7_1_Data_Panel_Hist';
3title 'Distribution of Cholesterol';
4PROC SGPANEL DATA=sashelp.heart(where=(ageatstart > 45 and weight_status ne 'Underweight')) noautolegend;
5panelby sex weight_status / layout=panel novarname headerattrs=(size=7);
6 histogram cholesterol;
7 density cholesterol;
8 rowaxis valueattrs=(size=7) labelattrs=(size=8);
9 colaxis valueattrs=(size=7) labelattrs=(size=8);
10RUN;
11title;
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.