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!
%let gpath='.'; /*--Put your Folder Name here--*/
%let dpi=300;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;
/*--Fig 2.7.1 Panel Scatter--*/
ods graphics / reset attrpriority=color noborder width=4in height=3in imagename='2_7_1_Data_Panel_Scatter';
title 'Cholesterol by Systolic';
proc sgpanel data=sashelp.heart(where=(ageatstart > 45 and weight_status ne 'Underweight')) noautolegend;
panelby sex weight_status / layout=panel novarname headerattrs=(size=7);
scatter x=cholesterol y=systolic / markerattrs=graphdata1(symbol=circlefilled) transparency=0.7;
reg x=cholesterol y=systolic / degree=2 nomarkers lineattrs=graphfit;
rowaxis valueattrs=(size=7);
colaxis valueattrs=(size=7);
run;
title;
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!
/*--Fig 2.7.2 Panel Histogram--*/
ods graphics / reset attrpriority=color noborder width=4in height=3in imagename='2_7_1_Data_Panel_Hist';
title 'Distribution of Cholesterol';
proc sgpanel data=sashelp.heart(where=(ageatstart > 45 and weight_status ne 'Underweight')) noautolegend;
panelby sex weight_status / layout=panel novarname headerattrs=(size=7);
histogram cholesterol;
density cholesterol;
rowaxis valueattrs=(size=7) labelattrs=(size=8);
colaxis valueattrs=(size=7) labelattrs=(size=8);
run;
title;
PROC SGPANELDATA=sashelp.heart(where=(ageatstart > 45 and weight_status ne 'Underweight')) noautolegend;
5
panelby 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);
10
RUN;
11
title;
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.