super demo: statistical graphics with ods · procedures create object with graph data, metadata ods...
TRANSCRIPT
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 1
Super Demo:Statistical Graphics with ODS
Presented by:
Cynthia Zender
2
Today's Topics Discuss differences between traditional SAS/GRAPH
procedures and ODS GRAPHICS Framework
Demonstrate selected examples of using ODS GRAPHICS ON/OFF with SAS/STAT procedures.
Demonstrate the new "SG" procedures: SGPLOT, SGPANEL, SGSCATTER and SGRENDER.
2
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 2
3
New Graph Production Methods
With ODS Statistical Graphics in SAS 9.2
– Statistical procedures create graphs as automatically as they create tables
– New SAS/GRAPH procedures streamline the process of making graphs for exploring data and making customized displays for novel types of analysis
3
4
ODS Statistical Graphics Functionality
Automates creation of graphs by statistical procedures that
have been modified to use ODS Graphics Procedures create object with graph data, metadata
ODS binds object with template description of graph
ODS renders graph
4
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 3
5
ODS GRAPHICS and the LISTING Destination
5
Method of CreatingGraphics for LISTING
Destination
ODS GRAPHICS
OFF
ODS GRAPHICS
ON
SAS/STAT procedure syntax (also, SAS/HPF, SAS/ETS and other procedures that support ODS Graphics)
Procedure options would impact style
Procedures always use style template information.
Graph Output Viewed GRAPH1 Window
Default Picture Viewer Application
Tabular Output Viewed Listing Window Listing Window
Image Format GRSEG entry PNG file
6
Sending a Graph to the SAS Graph1 WindowThe LISTING destination creates output that is placed automatically in the SAS Output Window (tabular output) or in the Graph1 Window (graphical output). In the SAS windowing environment, the SAS Output window is always open unless you close it.
6
Graphical Procedure
OutputODS LISTING
SAS Graph1 Window
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 4
7
Review GCHART ExampleConsider this SAS/Graph code:
7
proc gchart data=sashelp.heart;vbar deathcause / legend descending
subgroup=smoking_statusaxis = 0 to 650 by 50 name='LVbar';
format deathcause $dc.;run;quit;
8
GCHART ExampleThe GSTYLE option controls whether the SAS Style template is used for SAS/Graph procedures.
8
options nogstyle options gstyle=on;ods listing style=ocean;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 5
9
SAS/Graph Procedures and GSTYLE Option
9
Method of CreatingGraphics for LISTING
DestinationNOGSTYLE
OptionGSTYLEOption
SAS/Graph procedure syntax GOPTIONSand procedure syntax would impact style
Style template will set style, GOPTIONS and procedure syntax willoverride style template.
Graph Output Viewed GRAPH1 Window
GRAPH1 Window
Tabular Output Viewed Listing Window Listing Window
Image Format GSEG entry (with no style template informationused)
GSEG entry (with style template information used)
10
Output Creation with ODSWhen you create output files with ODS, all tabular and graphical output uses the active style template, as long as the GSTYLE option is turned on and the destination supports style templates.
10
ODS LISTING CLOSE;ODS destination FILE = "filename.ext" STYLE=egdefault;
SAS/Graph or SAS/STAT or other procedure code to generate a report
ODS destination CLOSE;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 6
11
HTML Syntax Model for Graphics CreationYou use slightly different syntax model for HTML-based destinations, which use an HTML <IMG> tag to point to a graphical image location.
11
ODS HTML PATH='<path for output>' (URL=NONE)GPATH='<path for images>' (URL=NONE)FILE = "filename.html" STYLE=egdefault;
SAS/Graph code to generate a report
ODS HTML CLOSE;
12
RTF and PDF Syntax Model Images for the RTF and PDF destinations are embedded in the ODS output file. There is no equivalent to an <IMG> tag for the RTF and PDF destinations.
12
ODS RTF FILE = "filename.rtf" STYLE=journal;SAS/Graph code to generate a report
ODS RTF CLOSE;
ODS PDF FILE = "filename.pdf" STYLE=journal2;SAS/Graph code to generate a report
ODS PDF CLOSE;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 7
13
Some Destinations Supported by ODS Graphics
Destination Viewer Graphics File Types
HTML Web browser PNG (default), GIF, JPEG, …
RTF Word processor, such as Microsoft Word
Embedded in RTF file
PS PostScript viewer, such as GSview
Embedded in PostScript file
PDF PDF viewer, such as Adobe Reader
Embedded in PDF file
LATEX PostScript or PDF viewer after compiling LaTeX file
PostScript (default), EPSI, GIF, JPEG, PDF, PNG
LISTING Default viewer in your system for file type
PNG (default), GIF, BMP, DIB, EMF, EPSI, JFIF, JPEG, …
13
14
Some Recommended Styles
Style Description
DEFAULT Color style intended for general-purpose work. This is the default for the HTML destination.
STATISTICAL Color style recommended for output in Web pages or color print media. This is the style used in SAS/STAT 9.2 documentation.
ANALYSIS Color style with a somewhat different appearance from STATISTICAL.
JOURNAL and JOURNAL2
Gray-scale and pure black-and-white styles, respectively. Recommended for graphs in black-and-white publications
RTF Used to produce graphs to insert into a Microsoft Word document or a Microsoft PowerPoint slide.
14
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 8
15
Statistical Procedures that Support ODS Graphics in SAS 9.2
Base SAS * SAS/STAT SAS/QC * SAS/ETS
CORR
FREQ
UNIVARIATE
ANOVA
BOXPLOT
CALIS
CLUSTER
CORRESP
FACTOR
FREQ
GAM
GENMOD
GLIMMIX
GLM
GLMSELECT
KDE
KDRIGE2D
LIFEREG
LIFETEST
LOESS
LOGISTIC
MCMC
MDS
MI
MIXED
MULTTEST
NPAR1WAY
PHREG
PLS
PRINCOMP
PRINQUAL
PROBIT
QUANTREG
REG
ROBUSTREG
RSREG
SEQDESIGN
SEQTEST
SIM2D
TCALIS
TRANSREG
TTEST
VARIOGRAM
ANOM
CAPABILITY
CUSUM
MACONTROL
PARETO
RELIABILITY
SHEWHART
ARIMA
AUTOREG
ENTROPY
EXPAND
MODEL
PANEL
RISK
SIMILARITY
SYSLIN
TIMESERIES
UCM
VARMAX
X12
15* experimental in SAS 9.2
16
PROC TRANSREG Example
16
ods graphics on;ods html style=statistical;proc transreg data=sashelp.cars plots=(all);
model BoxCox(msrp/convenient lambda=-2 to 2 by 0.05) =qpoint(horsepower MPG_Highway Weight);
run;ods html close;ods graphics off;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 9
17
PROC TRANSREG Example
17
ods graphics on;ods html style=statistical;proc transreg data=sashelp.cars plots=(all);
model BoxCox(msrp/convenient lambda=-2 to 2 by 0.05) =qpoint(horsepower MPG_Highway Weight);
run;ods html close;ods graphics off;
18
PROC TRANSREG Example
18
ods graphics on;ods html style=statistical;proc transreg data=sashelp.cars plots=(all);
model BoxCox(msrp/convenient lambda=-2 to 2 by 0.05) =qpoint(horsepower MPG_Highway Weight);
run;ods html close;ods graphics off;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 10
19
PROC TRANSREG Example
19
ods graphics on;ods html style=statistical;proc transreg data=sashelp.cars plots=(all);
model BoxCox(msrp/convenient lambda=-2 to 2 by 0.05) =qpoint(horsepower MPG_Highway Weight);
run;ods html close;ods graphics off;
20
PROC TRANSREG Example
20
ods graphics on;ods html style=statistical;proc transreg data=sashelp.cars plots=(all);
model BoxCox(msrp/convenient lambda=-2 to 2 by 0.05) =qpoint(horsepower MPG_Highway Weight);
run;ods html close;ods graphics off;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 11
21
PROC TRANSREG Example
21
ods graphics on;ods html style=statistical;proc transreg data=sashelp.cars plots=(all);
model BoxCox(msrp/convenient lambda=-2 to 2 by 0.05) =qpoint(horsepower MPG_Highway Weight);
run;ods html close;ods graphics off;
odsg01d01
22
PROC TRANSREG Example
22
ods graphics on;ods html style=statistical;proc transreg data=sashelp.cars plots=(all);
model BoxCox(msrp/convenient lambda=-2 to 2 by 0.05) =qpoint(horsepower MPG_Highway Weight);
run;ods html close;ods graphics off;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 12
23
PROC UNIVARIATE Defaults with ODSUsing PROC UNIVARIATE and the PPPLOT statement in SAS 9.2 with an ODS style template results in a probability plot that uses the ODS style template.
23
ods html path='.' (url=none)file='univ_orig.html' style=analysis;
proc univariate data=sashelp.heart;var AgeCHDdiag;ppplot;
run;
ods html close;
24
Univariate ExampleIf you submitted this PROC UNIVARIATE code with the PPPLOT statement, you could generate this output (viewed in a browser):
24
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 13
25
ODS Graphics ON/OFF and PROC UNIVARIATEThe same code using the ODS Graphics ON/OFF produces a slightly different result.
25
ods html path='.' (url=none)file='univ_orig.html' style=analysis;
ods graphics on;proc univariate data=sashelp.heart;var AgeCHDdiag;ppplot;
run;ods graphics off;ods html close;
ODS GRAPHICS ON/OFF support for PROC UNIVARIATE is experimental in SAS 9.2, Phase 2.
26
ODS Graphics and PROC UNIVARIATE
26 demo4
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 14
27
Compare Two Outputs
27
without ODS Graphics
with ODS Graphics
28
ODS Graphics and PROC UNIVARIATE
28
Output from ODS Graphics has title.Marker symbol circle (not plus).Analysis style colors and fonts used.
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 15
29
PROC REG
29
ods html path='.' (url=none)gpath='.'(url=none)file='reg_odsg.html' style=analysis;
ods graphics on / imagefmt=jpegimagename='Reg';
proc reg data=sashelp.heart;model Cholesterol = AgeCHDDiag;
quit; ods graphics off;
ods html close;
A PATH or GPATH value of '.' will direct all output to your current working directory.
30
PROC REG
30
ods html path='.' (url=none)gpath='.'(url=none)file='reg_odsg.html' style=analysis;
ods graphics on / imagefmt=jpegimagename='Reg';
proc reg data=sashelp.heart;quit; ods graphics off;
ods html close;ods html close;
A PATH or GPATH value of '.' will direct all output to your current working directory (C:\temp\output) in this case.
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 16
31
PROC REG Tabular Output
31
Tabular Results Viewed in Web Browser
32
PROC REG Graphic Output
32
Fit Diagnostics Paneled Image
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 17
33
PROC REG Graphic Output
33
Fit Diagnostics Paneled Image
Scatter Plot for Residuals
34
PROC REG Graphic Output
34
Fit Diagnostics Paneled Image
Scatter Plot for ResidualsFit Plot
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 18
35
PROC REG
35
ods html path='.' (url=none)gpath='.'(url=none)file='reg_select.html' style=analysis;
ods graphics on / imagefmt=jpegimagename='Reg';
ods select ParameterEstimates FitPlot;proc reg data=sashelp.heart;
model Cholesterol = AgeCHDDiag;quit; ods graphics off;
ods html close;
36
Results from ODS SELECT
36
Numbers will keep incrementing until index counter is reset.
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 19
37
Resetting the Index CounterTo reset the index, use the RESET=INDEX option of the ODS GRAPHICS ON statement.
37
ods html path='.' (url=none)gpath='.'(url=none)file='reg_reset.html' style=analysis;
ods graphics on / reset=indeximagefmt=pngimagename='Reg';
ods select FitStatistics FitPlot;proc reg data=sashelp.heart;
model Cholesterol = AgeCHDDiag;quit; ods graphics off;
ods html close;
38
Counter is ResetNote that the graphic image name does not have a numeric suffix.
38
If the JPEG image format had been selected, instead of PNG, this image would have overwritten the original Reg.jpeg file created in the first example.
Example 1
Example 2
Example 3
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 20
39
PROC ANOVA
39
ods html path='.' (url=none)gpath='.' (url=none)file='anova.html' style=analysis;
ods graphics on;
proc anova data = sashelp.heart;class Cholesterol;model AgeatDeath = Cholesterol;format cholesterol chst.;
run;quit;
ods graphics off;ods html close;
40
PROC ANOVA Tabular Output
40
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 21
41
PROC ANOVA Graphic Output
41
42
Graph Gallery for ODS Automatic Graphs with selected SAS/STAT Procedures
42
ods graphics on;
. . . SAS/STAT or SAS/ETS orSAS/HPF procedure of choice . . .
ods graphics off;
For more information about the appropriate syntax for your procedure of choice, consult the SAS/STAT documentation section entitled, “Statistical Graphics Using ODS”.
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 22
43
SAS/STAT Documentation Section
43
44
PROC REG Documentation
44
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 23
45
PROC BOXPLOT Documentation
45
46
Graph Gallery Main Effects Plot with GLM
46
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 24
47
Graph Gallery ANCOVA Plot with GLM
47
48
Graph Gallery Survival Plot with LIFETEST
48
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 25
49
Graph Gallery Residuals Plots with MIXED
49
50
Graph Gallery Component Plots with TIMESERIES
50
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 26
51
Graph Gallery Sliced Contour Plots with RSREG
51
52
Graph Gallery Bivariate Density Plot with KDE
52
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 27
53
Graph Gallery Bivariate Histogram with KDE
53
54
Graph Gallery Control Chart with SHEWHART
54
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 28
55
What Are The Statistical Graphics ProceduresWhen you use ODS GRAPHICS ON/OFF with statistical procedures, graphical output is automatically produced, based on the procedure syntax.
The new SAS/Graph statistical graphics procedures (also called the SG procedures) allow you to create statistically relevant graphical output without invoking a specific statistical procedure first. The SG procedures are:
SGPLOT
SGPANEL
SGSCATTER
SGRENDER.
55
56
SGPLOT OverviewThe SGPLOT procedure
creates one or more plots and overlays them on a single set of axes.
creates histograms, regression plots, scatter plots and line plots.
provides statements and options to control the appearance of your graph, including legends and reference lines.
56
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 29
57
SGPLOT ExamplesThe SGPLOT procedure syntax is very straightforward to use. Model syntax to create an HTML file is shown below:
57
<ODS DESTINATION OPEN statement>ODS GRAPHICS / imagename='name';
PROC SGPLOT DATA = libref.filenameDESCRIPTION= 'text-string';
. . . single or multiple SGPLOT Statements . . .RUN;
<ODS DESTINATION CLOSE statement>
The DESCRIPTION option is used for the HTML ALT= attribute of the <IMG> tag. The name for the image can be set with the IMAGENAME option of the ODS GRAPHICS statement. The ODS GRAPHICS environment is always ON when you use the SG procedures.
58
SGPLOT Gallery: VBAR StatementThe following syntax produces a VBAR chart.
58
proc sgplot data=sashelp.heart;vbar chol_status;
run;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 30
59
SGPLOT Gallery: VBAR StatementThe following syntax produces a VBAR chart.
HTML Outputusing OCEANstyle:
59
proc sgplot data=sashelp.heart;vbar chol_status;
run;
60
SGPLOT Program
60
The equivalent SGPLOT program to GCHART :
ods html path='c:\temp' (url=none)file='vbar_sgplot.html' style=analysis;
ods graphics on;proc sgplot data=heart;vbar deathcause / group=smoking_status ;format deathcause $dc.;
run;quit;. . . more code . . .
demo7
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 31
61
ods html path='c:\temp' (url=none)file='vbar_sgplot.html' style=analysis;
ods graphics on;proc sgplot data=heart;vbar deathcause / group=smoking_status ;format deathcause $dc.;
run;quit;. . . more code . . .
SGPLOT Program
61
The equivalent SGPLOT program to VBAR:
demo7
62
Different SGPLOT Program
62
A different SGPLOT with DATE variable (on stock information):
. . . more code . . .
proc sgplot data=ibm;vbar date / response=volume;
run;quit;ods graphics off;
ods html close;
demo7
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 32
63
Different SGPLOT Program
63
A different SGPLOT with DATE variable (on stock information):
. . . more code . . .
proc sgplot data=ibm;vbar date / response=volume;
run;quit;ods graphics off;
ods html close;
demo7
64
Plotting a Line
64
Adding a line plot only needs the VLINE statement::
ods html path='c:\temp' (url=none)file='sgplot_vline.html' style=analysis;
ods graphics on;
proc sgplot data=ibm;vbar date / response=volume;vline date / response=close y2axis;
run;
ods graphics off;ods html close;;
demo8
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 33
65
Plotting a Line
65
Adding a line plot only needs the VLINE statement::
ods html path='c:\temp' (url=none)file='sgplot_vline.html' style=analysis;
ods graphics on;
proc sgplot data=ibm;vbar date / response=volume;vline date / response=close y2axis;
run;
ods graphics off;ods html close;;
demo8
66
SGPLOT Gallery: VBOX StatementThe following syntax produces a VBOX chart.
66
proc sgplot data=sashelp.heart;vbox AgeatDeath / category=chol_status;
run;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 34
67
proc sgplot data=sashelp.heart;vbox AgeatDeath / category=chol_status;
run;
SGPLOT Gallery: VBOX StatementThe following syntax produces a VBOX chart.
HTML Outputusing OCEANstyle:
67
68
SGPLOT Gallery: REG StatementThe following syntax produces a REG plot.
68
proc sgplot data=sashelp.heart;reg x=cholesterol y=ageatdeath / CLM CLI;run;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 35
69
proc sgplot data=sashelp.heart;reg x=cholesterol y=ageatdeath / CLM CLI;run;
SGPLOT Gallery: REG StatementThe following syntax produces a REG plot.
HTML Outputusing OCEANstyle:
69
70
SGPLOT Gallery: SCATTER StatementThe following syntax produces a SCATTER plot with an ELLIPSE overlaid on the plot.
70
proc sgplot data=sashelp.heart;scatter x=AgeatDeath y=AgeCHDDiag; ellipse x=AgeatDeath y=AgeCHDDiag; keylegend / location=inside
position=bottomright;run;
Every statement produces output that is overlaid into the graph area. Therefore, your statements should be specified so that output from one statement does not overlay output from a previous statement.
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 36
71
SGPLOT Gallery: SCATTER StatementThe following syntax produces a SCATTER plot with an ELLIPSE and KEYLEGEND overlaid on the plot.
HTML Outputusing OCEANstyle:
71
proc sgplot data=sashelp.heart;scatter x=AgeatDeath y=AgeCHDDiag; ellipse x=AgeatDeath y=AgeCHDDiag; keylegend / location=inside
position=bottomright;run;
SCATTER
ELLIPSE
KEYLEGEND
72
Legends with Multiple PlotsIf you have multiple plot statements, not all legends will be shown.
72
ellipse x=cholesterol y=ageatdeath/ alpha=0.05;ellipse x=cholesterol y=ageatdeath/ alpha=0.25;ellipse x=cholesterol y=ageatdeath/ alpha=0.5;scatter x=cholesterol y=ageatdeath/ group=sex;
Automatic Legend
odsg04d04
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 37
73
Assigning Plot NamesWhen you assign names to your plot statements, you can control legend title, placement and appearance using the statement names in the KEYLEGEND statement.
73
proc sgplot data=odssg1.heart;where chol_status = 'High' and cholesterol gt 350;ellipse x=cholesterol y=ageatdeath / alpha=0.05 name='a05';ellipse x=cholesterol y=ageatdeath / alpha=0.25 name='a25';ellipse x=cholesterol y=ageatdeath / alpha=0.5 name='a50';scatter x=cholesterol y=ageatdeath / group=sex name='sc';title 'Using Multiple Legends with NAME= Values';keylegend 'a05' 'a25' 'a50'
/ title="Alpha Levels" across=1location=inside position=topright;
keylegend 'sc' / title="Gender" down=1location=outside position=bottom ;
run;
odsg04d04
74
KEYLEGEND Results
74
keylegend 'sc' / title="Gender" down=1location=outside position=bottom ;
keylegend 'a05' 'a25' 'a50' / title="Alpha Levels" across=1location=inside position=topright;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 38
75
SGPLOT Gallery: SERIES StatementThe following syntax produces two SERIES plots.
75
proc sgplot data=clinic_stats;where clinic contains 'East';series y=num_surg x=month / markers
curvelabel = ' Surgeries ' curvelabelloc=inside;
series y=tot_pts x=month / y2axis markers curvelabel = ' Patients ' curvelabelloc=inside;
xaxis label = 'Month' grid;yaxis label = 'Number Surgeries'
values=( 0 to 100 by 10) grid;y2axis label='Total Patients'
values=(0 to 1000 by 100);run;
76
SGPLOT Gallery: SERIES StatementThe following syntax produces two SERIES plots.
76
proc sgplot data=clinic_stats;where clinic contains 'East';series y=num_surg x=month / markers
curvelabel = ' Surgeries ' curvelabelloc=inside;
series y=tot_pts x=month / y2axis markers curvelabel = ' Patients ' curvelabelloc=inside;
xaxis label = 'Month' grid;yaxis label = 'Number Surgeries'
values=( 0 to 100 by 10) grid;y2axis label='Total Patients'
values=(0 to 1000 by 100);run;
HTML Output using OCEAN style:
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 39
77
Enhanced PlotThis INSET statement uses a single text string and options to place the inset text onto the graph.
77
inset "Includes data from Central and East clinics" /border position=top;
odsg04d01
78
Using a Title with the INSET TextWith the TITLE= option, you can give your inset box a title.
78
inset "Includes data from Central and East clinics" /border position=top title='Inset Title';
odsg04d01
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 40
79
Using Value Lists You can also use value lists with the INSET statement. The values can be hard-coded or supplied by macro variables.
79
inset (" Minimum" = "&minsurg" " Mean" = "&avgsurg" " Max"="&maxsurg") / bordertitle='Clinic Surgeries' position=top;
odsg04d01
80
Using Unicode CharactersYou can also insert Unicode characters into your INSET statement text. If you have macro variables that hold the values for mu and sigma:
80
ods escapechar='~';title 'Histogram and Density -- Framingham Heart Study';proc sgplot data = odssg1.heart;
histogram cholesterol;density cholesterol / type = normal;density cholesterol / type = kernel;inset ("~{unicode mu}"="&mn" "~{unicode sigma}"="&sd") /
position=topright border;run;
odsg04d01
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 41
81
SGPANEL OverviewThe SGPANEL procedure
creates a panel of graph cells for the values of one or more classification variables.
uses different layouts and panels to display multiple graphs.
displays the differing plot types and overlay plots in the graph cells based on default layouts or specific layouts.
provides several layout types for plot placement.
81
82
SGPANEL ExamplesThe SGPANEL procedure model syntax is shown below
82
<ODS DESTINATION OPEN statement>ODS GRAPHICS / imagename='name';
PROC SGPANEL DATA = libref.filenameDESCRIPTION="text-string";
PANELBY classification-variable(s) / <panel-options>;. . . single or multiple SGPANEL Statements . . .RUN;
<ODS DESTINATION CLOSE statement>
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 42
83
SGPANEL Gallery: PANELBY StatementThe following syntax produces a paneled chart.
83
proc sgpanel data=sashelp.heart;panelby sex; loess x=ageatdeath y=agechddiag /
clm alpha=.1;run;
(650)837‐7934(650)837‐7934
The statements that you can use with the SGPANEL procedure are generally the same as statements that you would use with the SGPLOT procedure. Consult the documentation to determine which plot statements can be used together in the SGPANEL procedure.
84
SGPANEL Gallery: PANELBY StatementThe following syntax produces a paneled chart.
HTML Outputusing OCEANstyle:
84
proc sgpanel data=sashelp.heart;panelby sex; loess x=ageatdeath y=agechddiag /
clm alpha=.1;run;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 43
85
SGPANEL Gallery: LAYOUT OptionsThe default LAYOUT option is the PANEL option. Other choices are COLUMNLATTICE, ROWLATTICE and LATTICE (for two classifications variables).
85
proc sgpanel data=sashelp.heart;panelby chol_status / layout=columnlattice
novarname; loess x=ageatdeath y=agechddiag /
clm alpha=.1;run;
86
SGPANEL Gallery: COLUMNLATTICE LayoutHTML Output using OCEAN style:
86
panelby chol_status / layout=columnlatticenovarname;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 44
87
SGPANEL Gallery: ROWLATTICE LayoutHTML Output using OCEAN style:
87
panelby chol_status / layout=rowlatticenovarname;
88
SGPANEL Gallery: LATTICE LayoutThe following syntax produces a panelled chart in a lattice layout using two classification variables.
88
proc sgpanel data=sashelp.heart;panelby chol_status sex /
layout=lattice novarname; loess x=ageatdeath y=agechddiag /
clm alpha=.1;run;
The LATTICE layout supports the use of exactly two classification variables. However, you can also use a BY statement, with the PANELBY statement to allow more flexibility.
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 45
89
SGPANEL Gallery: LATTICE LayoutHTML Output using OCEANstyle:
89
90
SGSCATTER OverviewThe SGSCATTER procedure
creates a panel of graph cells for the values of one or more classification variables.
uses different layouts and panels to display multiple graphs.
displays the differing plot types and overlay plots in the graph cells based on default layouts or specific layouts.
provides several layout types for plot placement.
90
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 46
91
SGSCATTER StatementsThe SGSCATTER procedure creates a paneled graph of scatter plots for multiple combinations of variables, depending on the plot statement that you use. The SGSCATTER produces graphs using one of these three statements:
PLOT statement
COMPARE statement
MATRIX statement.
91
92
SGSCATTER PLOT Statement ExampleThe PLOT statement creates multiple plots in a paneled layout.
92
proc sgscatter data=sashelp.heart;plot diastolic*agechddiag
diastolic*ageatdeath;run;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 47
93
SGSCATTER Example: PLOT StatementHTML Output using OCEAN style:
93
94
SGSCATTER COMPARE Statement ExampleThe COMPARE statement creates multiple plots in a paneled layout with a shared axis.
94
proc sgscatter data=sashelp.heart;compare x=(agechddiag ageatdeath)
y=(diastolic)/ group=chol_status ;
run;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 48
95
SGSCATTER Example: COMPARE StatementHTML Output using OCEAN style:
95
96
SGSCATTER MATRIX Statement ExampleThe MATRIX statement creates a scatter plot matrix. Each of the variables that you specify are graphed against each other to create the graph.
96
proc sgscatter data=sashelp.heart;where chol_status='High';matrix ageatdeath cholesterol weight /
diagonal=(histogram kernel);run;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 49
97
SGSCATTER Example: MATRIX StatementHTML Output using OCEAN style:
97
98
Using the SGRENDER ProcedureIf a Graph Template named "BOX_ELIP" has been created with PROC TEMPLATE syntax, it can be rendered with the following code:
98
ods html path='.' (url=none)gpath='.' (url=none)file='odssg01d13.html'style=ocean;
proc sgrender data=sashelp.hearttemplate=graph.box_elip;
where chol_status ne ' ';run;
ods _all_ close;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 50
99
HTML ResultsHTML Output using OCEAN style:
99
100
MORE ABOUT GRAPH TEMPLATES (SELF-STUDY)
100
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 51
101
SGRENDER OverviewThe SGRENDER procedure
produces graphical output from templates that are created with the Graph Template Language (GTL).
renders the GTL syntax and allows for the data to be bound to a graph template composed of more customized layouts and graphs that are beyond the scope of the Statistical Graphics procedures.
You can use the TMPLOUT= option with the SG procedures to create GTL syntax that can be modified and used with SGRENDER.
101
102
Deconstructing the Graph LayoutTo understand the Graph Template statements, it is useful to identify the text and layout areas on the graph:
102
EntryTitle
EntryFootnote
Column2Headers
ColumnHeaders
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 52
103
Layout SchematicThis is the conceptual layout schematic:
103
Column 1Layout/
Endlayout block for graph
Column 2Layout/
Endlayout block for graph
EntryFootnote Area
Layout Lattice statement to define 2 columns
Endlayout statement
Column2Headers Column2Headers
ColumnHeadersColumnHeaders
EntryTitle Area
104
Graph Template DefinitionEvery beginning statement must be ended.
104
proc template;define statgraph graph.box_elip;begingraph;EntryTitle, EntryFootnote statements
layout lattice;
layout overlay ;BoxPlot statements;
endlayout;
layout overlay ;ScatterPlot and Ellipse statements;
endlayout;
endlayout;
endgraph;end;run;
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 53
105
Graph Template DefinitionThe Graph Template definition uses PROC TEMPLATE.
105
proc template;define statgraph graph.box_elip;begingraph;EntryTitle "Want to Use GTL" /; EntryFootnote "EntryFootnote to Span Both Graphs";
layout lattice / columns=2 columngutter=10;column2headers;entry "Boxplot";entry "Prediction Ellipse";
endcolumn2headers;
columnheaders;entry "Graph 1";entry "Graph 2";
endcolumnheaders;
Begin StatGraph Definition
106
Graph Template DefinitionThe Graph Template definition uses PROC TEMPLATE.
106
layout overlay / yaxisopts=( Label="Age At Death" type=linear linearopts=( tickvaluelist=( 40 60 80 100 )
viewmin=35 viewmax=100 ) );BoxPlot X=chol_status Y=AgeAtDeath /
SortOrder=Data primary=true LegendLabel="Age at Death" NAME="VBOX";
endlayout;
end Boxplot Layout
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 54
107
Graph Template DefinitionThe Graph Template definition uses PROC TEMPLATE.
107
layout overlay / yaxisopts=( Label="Age At Death" type=linear linearopts=( tickvaluelist=( 40 60 80 100 )
viewmin=35 viewmax=100 ) );ScatterPlot X=Weight Y=AgeAtDeath /
primary=true Group=Chol_Status LegendLabel="Age at Death" NAME="SCATTER";
Ellipse X=Weight Y=AgeAtDeath / Type=Predicted LegendLabel="95% Prediction Ellipse" NAME="ELLIPSE";
DiscreteLegend "SCATTER"/ Location=Outside halign=center valign=bottom;
endlayout;endlayout;endgraph;end;run;
end Scatterplot Layout
end Lattice Layout
end Statgraph definition
108
More About Graph Templates
Graph templates are programs, written in the Graph Template Language, that describe individual graphs.
SAS provides a default template for every graph produced by a procedure, so you never need to write a template!
You can modify the default templates to make persistent changes that apply every time you run your program.
You can also modify the template code generated by the SG procedures to make custom graphs for use with the SGRENDER procedure.
108
ODS Graphics Super Demo
Copyright © 2010, SAS Institute Inc. All rights reserved. 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 55
109
Summary: Two Ways to Modify Your Graphs
Graph Template Changes ODS Graph Editor
Appropriate for SAS programmer familiar with the Graph Template Language
Statistical end user
Approach Programming Point-and-click
Type of change Persistent Immediate
Duration Whenever program is re-run Current graph only
Application Batch processing of graphs Papers, presentations
Approach Programming Point-and-click
File saved Modified graph template PNG or SGE
109