Examples of Using the Procedures

SGPLOT Examples

Example Fit Plot

If you calculate a custom fit for your data, you might use a series plot to render the fit. The following PROC SGPLOT example combines a scatter and a series plot, and uses the SASHELP.CLASSFIT data set.
Example Output for the FIT Plot
Output for the FIT Plot
proc sgplot data=sashelp.classfit  noautolegend;
scatter x=height y=weight;
series x=height y=predict; 
run;
The NOAUTOLEGEND option in the SGPLOT statement disables the legend that is generated automatically for the graph. Without this statement, the graph would have an unnecessary legend, as seen below.
FIT Plot with an Unnecessary Legend
FIT Plot with an Unnecessary Legend

Example Bar Chart

The following horizontal bar chart shows cumulative product orders for a clothing store.
Bar Chart That Shows Cumulative Product Orders
Bar Chart that Shows Cumulative Product Orders
In the SGPLOT procedure, the HBAR statement specifies the plot to be displayed, which in this case is a horizontal bar chart. In addition, the statement specifies the response variable (Number of Items) to be displayed on the horizontal axis. The response variable is optional. If you do not provide a response variable, then the chart shows the frequency count on the horizontal axis. The statement also specifies the statistic for the horizontal axis. The STAT= option enables you to specify the sum, the mean, or the frequency for the response variable.
proc sgplot data=sashelp.orsales; 
  format Quantity comma7.;
  hbar Product_Category / response = Quantity stat=sum;
run;
Note also that the SGPLOT procedure supports the FORMAT statement, along with several other global SAS statements.

SGPANEL Example

The following example shows a panel of regression curves.
Output for a Regression Plot
Output for a Regression Plot
The COLUMNS= option in the PANELBY statement specifies that the panel has three columns of graph cells. The example uses the REG statement to create the regression curve. The CLI option creates individual predicted value confidence limits. The CLM option creates mean value confidence limits.
proc sgpanel data=sashelp.iris;
  title "Scatter plot for Fisher iris data";
  panelby species / columns=3;
  reg x=sepallength y=sepalwidth / cli clm;
run;
title;