Lesson 15: Creating Graphs Using SAS/GRAPH Software Summary

Lesson 15: Creating Graphs Using SAS/GRAPH Software
Summary
Main Points
Overview of SAS/GRAPH Software
SAS/GRAPH software is an additional SAS component that you can use with Base SAS to
produce many kinds of charts, plots, and maps in both two- and three-dimensional views.
To produce a SAS/GRAPH report, you begin by specifying a GOPTIONS statement to set
any global options that you want for your graphs. Then you add other global statements such
as TITLE and FOOTNOTE statements. Next, you write the PROC step for the specific type
of graph you want. To end the procedure, you use a QUIT statement.
Specifying Global Statements in SAS/GRAPH Programs
GOPTIONS <options-list>;
You use the GOPTIONS statement to control graphics options that apply to all graphs. To
reset all graphics options, you specify RESET=ALL in the GOPTIONS statement. You can
also set specific options; for example, you can set CBAK=WHITE to set the background
color to white.
You can use other global statements in your SAS/GRAPH programs, such as TITLE and
FOOTNOTE statements.
Creating Bar and Pie Charts
PROC GCHART DATA=SAS-data-set;
chart-form chart-variable </ options>;
RUN;
In the PROC GCHART step, you specify the chart form such as VBAR, VBAR3D, HBAR,
HBAR3D, PIE, or PIE3D. You can specify multiple forms.
By default, the size of the bars or pie slices in a chart represents a frequency count of the
values of the chart variable.
PROC GCHART creates a bar for each midpoint, which is a value that represents either one
data value of the middle of a range of data values.
You can specify options in the statement that defines the form of the bar or pie chart, such as
the NOSTATS option, the AUTOREF option, the LEVELS= option, the RANGE option, and
the DISCRETE option.
SAS® Programming 1: Essentials
Copyright © 2010 SAS Institute Inc., Cary, NC, USA. All rights reserved.
1
Lesson 15: Creating Graphs Using SAS/GRAPH Software
You can use the TYPE= option to specify a statistic other than the default statistic FREQ. For
bar charts, you can specify FREQ, CFREQ, PERCENT, or CPERCENT.
You can use the SUMVAR= option to summarize a variable for each unique value of the
chart variable. The SUMVAR= option specifies the variable whose values control the height
or length of the bars; this variable is known as the summary variable or the analysis variable.
You can use the TYPE= and SUMVAR= options together, but in that case the value of
TYPE= must be either SUM or MEAN.
You can add a LABEL statement to a PROC GCHART step to specify labels for the chart.
You can also specify other statistics to display above or to the right of the bars, including
SUM, FREQ, and PERCENT.
Other options you can use with your bar charts include the PATTERNID=MIDPOINT
option, the SUBGROUP= option, and the GROUP= option.
When you create pie charts, you can also use options such as SUMVAR=, TYPE=, GROUP=
and SUBGROUP=.
Creating Plots
PROC GPLOT DATA=SAS-data-set;
PLOT vertical-variable*horizontal-variable </ options>;
SYMBOL<1…255> <options>;
RUN;
You can use the GPLOT procedure to create plots of one variable plotted on the horizontal
axis and a second varaible plotted on the vertical axis. PROC GPLOT can create single plots
and overlay plots.
You can use other statements such as the FORMAT statement and the LABEL statement
within a PROC GPLOT step.
The SYMBOL statement specifies plotting symbols, plot lines, and color. You can use
multiple SYMBOL statements within one PROC GPLOT step. In the SYMBOL statement,
you can use the options C=, I=, CV=, and CI=.
To overlay plots on the same set of axes, you use a PLOT statement that specifies two
separate plot requests, and you use the OVERLAY option.
You can use options in the PLOT statement such as the VREF= option, the CFRAME=
option, and the HAXIS= and VAXIS= options.
SAS® Programming 1: Essentials
2
Lesson 15: Creating Graphs Using SAS/GRAPH Software
Enhancing SAS/GRAPH Output
ODS destination STYLE=style-definition;
You can apply styles to your charts. Remember that you use the STYLE= option in the ODS
statement to specify an ODS style.
You can add the FTEXT=, CTEXT=, and HTEXT= options to the GOPTIONS statement to
control the appearance of all text in the graph.
You can add options to other global statements such as the TITLE statement and
FOOTNOTE statement to control the appearance of your text. You can use the FONT=,
COLOR=, HEIGHT=, or JUSTIFY= options.
Using RUN-Group Processing
A RUN-group is a group of statements that contains at least one action statement and ends
with a RUN statement. By using RUN-group processing, you can produce multiple graphs
without resubmitting the PROC statement every time.
Sample Code
Creating Bar and Pie Charts
goptions reset=all border;
title 'Employees by Job Title';
proc gchart data=orion.staff;
vbar3d Job_Title / sumvar=salary type=mean mean;
where Job_Title=:'Sales Rep';
label Salary='Average Salary'
Job_Title='Job Title';
run;
quit;
SAS® Programming 1: Essentials
3
Lesson 15: Creating Graphs Using SAS/GRAPH Software
Creating Plots
proc gplot data=orion.budget;
plot Yr2006*Month yr2007*Month/ overlay vref=3000000
cframe='#FFFFE0' vaxis=1000000 to 5000000 by 1000000;
haxis=1 to 12;
format Yr2006 dollar12.;
label Yr2006='Budget';
symbol1 i=join v=dot ci=blue cv=blue;
symbol2 i=join v=triangle ci=red cv=red;
run;
Enhancing SAS/GRAPH Output
ods html style=gears;
goptions reset=all ftext=arial ctext=dark_blue htext=6 pct;
proc gchart data=orion.staff;
pie3d Job_Title;
where Job_Title=:'Sales Rep';
label Gender='Gender'
Job_Title='Job Title';
title f=centbi h=5 pct 'Budget by Month';
footnote c=green j=left 'Data for 2007';
run;
SAS® Programming 1: Essentials
4
Lesson 15: Creating Graphs Using SAS/GRAPH Software
Using RUN-Group Processing
proc gchart data=orion.staff;
vbar Job_Title;
title 'Bar Chart of Job Titles';
run;
pie3d Job_Title;
title 'Pie Chart of Job Titles';
run;
proc gplot data=orion.budget;
plot Yr2006*Month;
symbol1 i=join v=dot ci=blue cv=blue;
symbol2 i=join v=triangle ci=red cv=red;
run;
quit;
SAS® Programming 1: Essentials
5