/* / Program : Easy Graphing in SAS / Version : 0.1 / Editor(s) : Nicole M Lindner / Date : March 18, 2009 / Contact : nml5d@virginia.edu /====================================================================================================== / Purpose : Demostrate simple, attractive graphing in SAS / Direct collaborators to useful resources that will help you quickly generate / high-quality SAS graphs to accompany typical statistical analysis / Notes : This script shows you how to do Point-and-click graphing in SAS / /====================================================================================================== / PARAMETERS: /-------name----------- -------------------------description------------------------------------------- / Point-click-graphs Uses SAS' new ACTIVEX driver to enclose a simple graph. / With this, you can then right-click to change axes/ ranges, colors, / etc (similar to SPSS) / * Example2 - Simplified version of 2x2 anova with defaults / * Example3 - From SAS-Help Area bar, with subgrouping / * Example4 - Comparative histogram - Plots the distribution of data / across a given class variable / / ODS GRAPHICS INTRO Intro to SAS' new abilities to automatically generate graphs when you / run certain statistical procedures. Also points you to other / resources that explain these in more detail. / /* *************************************************************************************************** Point-click-graphs ************************************************************************************************ */ /*** Initializing the graphics options as an activeX device driver; This allows you to mouse-over areas for information, and to double-click on a given element to change its formatting. As far as I can tell, the closest to point-and-click graphing in SAS ***/ goptions device=activex ; /* This is the essential part to use */ filename grafout 'C:\Documents and Settings\nml5d\My Documents\Age data\MaxNet\Huskey'; /*** The filename tells SAS where I want to store the output (note that it's a folder and that the HTML statements needs the PATH= (with the folder) and FILE= (with the name of the file for the output) specified ***/ ODS HTML CLOSE; ODS HTML FILE="C:\Documents and Settings\nml5d\My Documents\Age data\MaxNet\Huskey\twoxtwo.ANOVA.html"; /*** NOTE IMPORTANT ***/ SYMBOL1 INTERPOL=STD1MTJ C=grey MODE=INCLUDE line=1; /* For a regression line instead, just say INTERPOL=R instead */ /*** Interpol Connects the means, with SE bars; unless axes contain full range of data, must use MODE=INCLUDE Or SAS will only use values that fall within the plotted range to calculate the SE bars & mean ***/ /*** Example 2 - Simplified line graph of 2x2 anova, allowing SAS' default graphing ***/ /*** For help with all the changes you can make with this, look at the graph in the Results Viewer, then right-click --> Help --> Graph Control Help ***/ TITLE1 "2x2 ANOVA - defaults"; SYMBOL1 INTERPOL=STD1MTJ C=grey MODE=INCLUDE line=1; SYMBOL2 INTERPOL=STD1MTJ C=black MODE=INCLUDE line=1; PROC GPLOT DATA=Huskey; PLOT Hire*UC2=CandOld / noframe ; RUN;QUIT; ODS HTML CLOSE; TITLE1 "SAS Example"; ODS HTML FILE="C:\Documents and Settings\nml5d\My Documents\Age data\MaxNet\Huskey\Sas.Example.ANOVA.default.html"; /*** Example 3 - From SAS-Help Area bar, with subgrouping ***/ proc gareabar data=sashelp.prdsale; hbar product*predict /sumvar=actual subgroup=country rstat=SUM wstat=PCT ; run;quit; /* proc contents data=sashelp.prdsale;run; */ ODS HTML CLOSE; /*** Example4 - Comparative histogram ***/ /* Plots the distribution of data across a given class variable For whatever reason, you have to include in the VAR statement (even though the NOPRINT option means it doesn't send the info to the output window before you can run a histogram. I'm doing a few simple things to force it to show the full range of the scale (with midpoints) */ ODS HTML FILE="C:\Documents and Settings\nml5d\My Documents\Age data\MaxNet\Huskey\Comparative.Histograms.html" STYLE=Analysis; /* ODS HTML STYLE= Tells SAS to use a particular color/ etc. scheme (Style) For ODS GRAPHICS, SAS recommends that you use STYLE= Analysis Default Journal Statistical */ /* / NORMAL adds a normal curve to the data (a black line) */ PROC UNIVARIATE NOPRINT DATA=Huskey;CLASS CandOld;VAR Q01 Q02 Q03; HISTOGRAM Q01 Q02 Q03 / NORMAL(COLOR=BLACK) MIDPOINTS= 1 TO 6 BY 1 VSCALE =PERCENT NOFRAME ; RUN;QUIT; ODS HTML CLOSE; /* *************************************************************************************************** ODS GRAPHICS Intro ************************************************************************************************ */ /*** Generating graphs automatically for several SAS/STAT procedures in SAS 9. To see all of the available graphics (SAS calls them ODS GRAPHICS), see: http://support.sas.com/rnd/base/topics/statgraph/proctemplate/a002787622.htm In SAS 9.1, it should include graphics for at least these procedures: CORR, ANOVA, GLM, LOESS, LOGISTIC, MIXED, REG To get the graph you simply turn ODS GRAPHICS ON and then choose the graph required . Here's an example: ***/ data Class; input Name $ Height Weight Age @@; datalines; Alfred 69.0 112.5 14 Alice 56.5 84.0 13 Barbara 65.3 98.0 13 Carol 62.8 102.5 14 Henry 63.5 102.5 14 James 57.3 83.0 12 Jane 59.8 84.5 12 Janet 62.5 112.5 15 Jeffrey 62.5 84.0 13 John 59.0 99.5 12 Joyce 51.3 50.5 11 Judy 64.3 90.0 14 Louise 56.3 77.0 12 Mary 66.5 112.0 15 Philip 72.0 150.0 16 Robert 64.8 128.0 12 Ronald 67.0 133.0 15 Thomas 57.5 85.0 11 William 66.5 112.0 15 ; /*** Plots fit diagnostics as well ***/ /*** Regression example, with diagnostics ***/ ODS HTML FILE="C:\Documents and Settings\nml5d\My Documents\Age data\MaxNet\Huskey\SasEx.Regression.html"; ODS GRAPHICS ON; PROC REG DATA= Class PLOTS(UNPACKPANELS); MODEL Weight = Height; RUN;QUIT; ODS GRAPHICS OFF; ODS HTML CLOSE; /*** This is just to get you started. See here for a run-through of several graphs that are possible with statistical procedures http://www.lexjansen.com/pharmasug/2008/tu/tu04.pdf ***/