Great Using Proc Sgplot, Proc Sgscatter, and ODS for SAS ... · PDF fileGreat Graphics Using Proc Sgplot, Proc Sgscatter, and ODS Graphics for SAS®/Stat Procedures Kathy Welch CSCAR

Embed Size (px)

Citation preview

  • GreatGraphicsUsingProcSgplot,ProcSgscatter,andODSGraphicsfor

    SAS/StatProcedures

    KathyWelchCSCAR

    TheUniversityofMichiganMSUGMeeting,TuesdayApril27,2010

  • WhatwewillCover IntroductiontoStatisticalGraphicsProcedures

    ProcSgplot ProcSgscatter ProcSgpanel

    EditingODSgraphicsfiles ExamplesofODSgraphicswithStatisticalProcedures

    Procttest ProcReg ProcGLM ProcLogistic

  • StatisticalGraphicsUsingProcSgplot,ProcSgscatterandProcSgpanel

    StatisticalgraphicsplotsuseODS(outputdeliverysystem)graphics

    Statisticalgraphicsareeasytoproduce,looknice,andaremoreintuitivethantraditionalSAS/Graphgraphics

    StatisticalGraphicscanbeedited(tosomeextent)interactively

  • Wherearemygraphs? GraphscreatedwithODSgraphicswillbeinResultsWindow,notinGraphWindow

    Doubleclickonthegraphicsicontoviewthefile,usinglocalwindowsgraphicsviewer.

    Graphswillbeautomaticallybesavedas.pngfilesincurrentSASfolder

    png(portablenetworkgraphics)filesare Rastergraphics Compactformat Usableinmostwindowsapplications

  • GettingStarted

    2. Double-click on graphics file icon to view graph 1. Set the current folder

  • Boxplotsprocsgplotdata=mylib.employee;

    vboxsalary;run;

  • BoxplotsforCategoriesprocsgplotdata=mylib.employee;vboxsalary/category=gender;run;

  • PaneledBoxplotsprocsgpaneldata=mylib.employee;panelbyjobcat/rows=1columns=3;vboxsalary/category=gender;run;

  • Barcharts

    procsgplotdata=mylib.employee;vbarjobcat;run;

  • StackedBarchartsprocsgplotdata=mylib.employee;vbarjobcat/group=Gender;run;

  • BarchartswithMeansandErrorBarsprocsgplotdata=mylib.employee;vbarjobcat/response=salarylimitstat=stddevlimits=upperstat=mean;run;

  • BarchartsofProportionsprocsgplotdata=afifi;vbarshoktype/response=diedstat=mean;formatshoktypeshokfmt.;run;

  • PaneledBarchartsprocsgpaneldata=mylib.employee;panelbygender;vbarjobcat/response=salarylimitstat=stddevlimits=upperstat=mean;run;

  • Histogramsprocsgplotdata=mylib.employee;histogramsalary;densitysalary;densitysalary/type=kernel;keylegend/location=insideposition=topright;

  • OverlaidHistogramsprocsgplotdata=mylib.employee;histogramsalbegin;histogramsalary/transparency=.5;run;

    Note: Transparency = 0 is opaque. Transparency = 1.0 is fully transparent.

  • Scatterplotsprocsgplotdata=mylib.employee;scatterx=salbeginy=salary/

    group=gender;run;

  • ScatterplotwithRegressionLineprocsgplotdata=mylib.employee;wherejobcat=1;scatterx=prevexpy=salary/group=gender;regx=prevexpy=salary/cliclmnomarkers;run;

  • RegressionLinesforSubgroupsprocsgplotdata=mylib.employee;wherejobcat=1;regx=prevexpy=salary/group=gender;run;

  • PaneledScatterplotwithLoessFitprocsgpaneldata=mylib.employee;panelbyjobcat/columns=3;scatterx=jobtimey=salary/group=gender;loessx=jobtimey=salarynomarkers;run;

  • ScatterplotMatrixprocsgscatterdata=mylib.employee;wherejobcat=1;matrixsalbeginsalaryjobtimeprevexp/group=gender

    diagonal=(histogramkernel);run;

  • SeriesPlotsprocsgpaneldata=autism;panelbysicdegp/columns=3;seriesx=agey=vsae/group=Childidmarkerslegendlabel=""lineattrs=(pattern=1color=black);

  • GenerateMeansprocsortdata=autism;bysicdegpage;run;procmeansdata=autismnoprint;bysicdegpage;outputout=meandatmean(VSAE)=mean_VSAE;run;dataautism2;mergeautismmeandat(drop=_type__freq_);bysicdegpage;run;

  • MeanPlotsOverlaidonRawDataprocsgplotdata=autism2;seriesx=agey=mean_VSAE/group=SICDEGP;scatterx=agey=VSAE;run;

  • FormatsMakeGraphsMoreReadable

    proc format;value jobcat 1="Clerical"

    2="Custodial"3="Manager";

    value $Gender "f"="Female""m"="Male";

    run;

  • FormatsMakeGraphsMoreReadable2

    proc sgpanel data=mylib.employee;panelby jobcat / rows=1 columns=3 novarname;vbox salary / category= gender ;format gender $gender. jobcat jobcat; run;

  • EditingODSGraphics

    Usesgedit,orsgediton toenableODSgraphicseditor Submitincommanddialogbox

    Twooutputswillbecreatedforeachgraph. .pngfile .sge(SASGraphicsEditor)file

    Editthe.sgefile,andsaveasa.pngtouseinotherapplications.

  • SomeoftheThingsyoucanEditwiththeODSGraphicsEditor

    Title,footnote Axislabels,colors,fonts,symbols,textboxes GraphStyle(Trythem)

    Listing(thedefault,colors) Analysis(colorscheme) Journal(grayscale) Journal2(blackandwhite) Statistical(colorscheme)

  • SASGraphicsEditorWindow

  • CreatingPDFOutput Sendoutputtoapdffile SimilarforHTMLorrtffileoutput

    odspdfstyle=journal2;odspdffile="testing.pdf";odslistingclose;title"PDFOutput";procsgpaneldata=mylib.employee;panelbyjobcat;scatterx=jobtimey=salary/group=gender;loessx=jobtimey=salary/nomarkers;run;

    odspdfclose;odslisting;

  • PDFOutputwillbeintheResultsViewerWindow

  • WheretoGetHelpforStatisticalGraphicsProcedures

    SASHelpandDocumentation>Contents>SASProducts>SAS/Graph>SAS/Graph9.2StatisticalProceduresGuide>SAS/GraphStatisticalGraphicsProcedures

    Onceyoufindit,itsreallyhelpful.

  • ODSGraphicsinSAS/StatProcedures

    ODSgraphicsareavailableforstatisticalprocedures

    Submitodsgraphicson; beforetheprocedure Submitodsgraphicsoff; aftertheprocedure Graphsare.pngfiles,asforProcSgplot,SgscatterandSgpanel.

    ODSgraphicsshowupafterdrillingdown intheResultswindowfortheprocedure.

    CheckSASdocumentationforavailableODSgraphicsforeachprocedure

  • Procttestodsgraphicson;procttestdata=mylib.afifi;classsurvive;varsbp1;run;odsgraphicsoff;

  • ProcRegodsgraphicson;title"RegressionwithDefaultPlots";procregdata=mylib.afifi;modelsbp2=sbp1sexage/partial;run;quit;odsgraphicsoff;

  • ProcRegUnpackGraphicsprocregplots(only)=DiagnosticsPanel(unpack);

  • ProcGLM

    odsgraphicson;title"AnovawithPlots";procglmdata=mylib.afifi;classshoktype;modelsbp1=shoktype;lsmeansshoktype/pdiffadjust=tukey;run;quit;odsgraphicsoff;

  • ProcGLMDiffPlot

  • ProcLogisticodsgraphicson;proclogisticdata=mylib.afifidescendingplots(only)=(effectroccurve);classshoktype;modelsurvive=sbp1shoktype;outputout=preddatp=predictreschi=rchi

    resdev=rdevh=leverage;

    run;quit;odsgraphicsoff;

  • ProcLogisticROCCurveandEffectPlot

  • Thankyou!

    Trysomeofthesegraphsusingyourdata. Theyreeasyandfun!