Chapter 8: ODS Graphics ODS graphics were not available prior to SAS 9.2 They have been implemented across a wide range of procedures Functionality isn’t consistent © Fall 2011 John Grego and the University of South Carolina
Saving graphs Graphs can be routed to different devices (default is LISTING) For default output, graphs are available in the Results window as separate objects The default graph type is .png; it can be modified to .jpg, etc Some style choices are readily edited © Fall 2011 John Grego and the University of South Carolina
Customizing saved graphs ODS LISTING with the GPATH option can save graphs as single documents in a variety of formats. ODS GRAPHICS uses IMAGENAME to personalize graph names Format, size and resolution can also be specified. Once GPATH is set, the number of graphs with similar names can proliferate. Wait till first chart to run ODS LISTING and ODS GRAPHICS code. © Fall 2011 John Grego and the University of South Carolina
PROC SGPLOT Omnibus procedure to create ODS graphics We will review Bar charts Histograms and box plots Scatterplots Time series plots Fitted curves
PROC SGPLOT-Bar Charts Creates vertical or horizontal bar charts Groups can be added Bars can actually be summary statistics for continuous variables PROC SGPLOT; VBAR varname/ GROUP=catname; RESPONSE=varname STAT=stattype; LABEL varname=‘varlabel; Run SGPlotChart.sas
PROC SGPLOT-Histograms SCALE subcommand graphs percents, counts, or proportions on the vertical axis DENSITY overlays a normal curve (default) or kernel density estimate PROC SGPLOT; HISTOGRAM varname; DENSITY varname; DENSITY varname/TYPE=kernel; Default is PERCENT
PROC SGPLOT-Boxplots VBOX specifies graphing variables CATEGORY generates side-by-side plots PROC SGPLOT; VBOX varname/ CATEGORY=catvarname; Run SGPlotHist.sas
PROC SGPLOT-Scatter Plots Alternative to PROC GPLOT Multiple SCATTER statements produce overlaid plots LABEL improves the legend for overlaid plots GROUP creates different plotting symbols PROC SGPLOT; SCATTER X=hname Y=vname; GROUP=groupname; XAXIS LABEL=‘xlabel’ VALUES=(low TO high BY increment); Run Anscombe data. Run SGPlotPlot.sas in parts.
PROC SGPLOT-Time Series Plots Data points are connected by lines by default The horizontal axis will be time, date, etc LABEL command for dates follows naming conventions we have seen before PROC SGPLOT; SERIES X=timeindex Y=vname; GROUP=groupname; XAXIS LABEL=‘xlabel’ VALUES=(‘ddmmmyy’d TO ‘ddmmmyy’d BY increment); Run Broad River code.
PROC SGPLOT-Fitted Curves A scatterplot is automatically generated for REG, LOESS, or PBSPLINE CLM adds confidence bounds NOMARKER suppresses the oft-redundnat printing of the scatter plot PROC SGPLOT; REG X=hname Y=vname; LOESS X=hname Y=vname; PBSPLINE X=hname Y=vname; Run R script and run rest of Anscombe. Read in Faithful.xlsx and run faithful code.
Controlling SGPLOT features In addition to some of the features already discussed, we can reference lines (REFLINE), change the position of legends (KEYLEGEND), and add embedded text (INSET). We can also customize graph feature attributes (MARKERATTRS, LINEATTRS, LABELATTRS, FILLATTRS, etc)
PROC SGPANEL Panel graphs are an increasingly preferred alternative to traditional methods for multi-graph displays. PROC SGPANEL ; PANELBY variable-list; SCATTER X=hname Y=vname; SERIES X=index Y=vname; Etc.