Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to SAS ODS Graphics September 16, 2015 Rocio Lopez.

Similar presentations


Presentation on theme: "Introduction to SAS ODS Graphics September 16, 2015 Rocio Lopez."— Presentation transcript:

1 Introduction to SAS ODS Graphics September 16, 2015 Rocio Lopez

2 Overview Introduction Basic Set-Up SAS Automatic Graphs SG Procedures – SGPlot – SGPanel – SGScatter Take away message Future Talks

3 INTRODUCTION

4 Introduction Until version 9 all graphics were done with SAS/GRAPH procedures (gplot, gchart, etc.) http://support.sas.com/resources/papers/proceedings15/2441-2015.pdf

5 Introduction ODS graphics – Developed to make it easier to generate common graphics. – Features: – Graphics capabilities added to statistical procedures – SG procedures – Graphics Template Language (GTL) – ODS Graphics Designer & Editor 9.3 and 9.4 (including maintenance releases) have made lots of improvements and additions

6 Some Examples

7 SET-UP

8 Set-up Request graphs ods graphics on; proc statements; ods graphics off; In SAS 9.4 ODS graphics are generated by default. Where to view graph – Results window – Depending on ods destination – stand alone figure – embedded figure in.rtf or.pdf file

9 Modifying destination and resolution

10 Modify graph options ods graphics ;

11 Modify graph options OptionDescription border|noborder border=on|off Control border around graph height=480px Height of graph. Accepted units are cm, in, mm, pct, pt, px. imagename="filename"Specify file name reset Reset all options to default values. To reset particular options use reset=option scale|noscale scale=on|off Specify whether the content of the graph is scaled proprotionally width=dimensionWidth of graph outputfmt=file-type Specify output format. This varies by ODS destination See User Guide for full list

12 Supported file types

13 Set-up – Recap ods listing gpath=“&GraphDir.” image_dpi=300; ods graphics / reset imagename=“Figure1” scale=on width=3in height=3in; proc statements; ods graphics off; Only need to resubmit these statements if you wish to change any of the options for next graph

14 AUTOMATIC GRAPHS

15 Automatic Graphs From Procedures Starting with SAS 9.2 many analytical procedures automatically generate certain graphs ods rtf file=“ProcRegExp.rtf” style=journal; ods graphics on; proc reg data=sashelp.class; model Weight = Height; run; ods graphics off; ods rtf close;

16 SGPLOT PROCEDURE

17 SGPLOT Procedure Single-cell graphs Supports over 20 different plot statements You can combine most plot statements in the same graph – Overlaid in order specified Supporting statements allow more customizations – Reference lines – Insets – Axes – Axes tables – Legends

18 SGPLOT Procedure - Syntax proc sgplot data= ; plot-statement(s) required-parameters ; ; run;

19 SGPLOT - Histogram proc sgplot data=sashelp.class; histogram age; run;

20 SGPLOT – Histogram & Density proc sgplot data=sashelp.class; histogram age; density age; run;

21 SGPLOT – Histogram (move legend) proc sgplot data=sashelp.class; histogram age; density age; keylegend / location=inside position=topright noborder; run;

22 SGPlot – Box Plot proc sgplot data=sashelp.class; hbox height/category=sex; run; proc sgplot data=class; vbox height/category=sex group=Over13; run;

23 SGPlot – Bar chart proc sgplot data=sashelp.cars; vbar type/stat=percent; run; proc sgplot data=sashelp.cars; hbar type/stat=percent; run;

24 SGPlot – Bar chart (add data label and change axis) proc sgplot data=sashelp.cars; vbar type/stat=percent datalabel; yaxis values=(0 to 0.6 by 0.1) max=0.65 valueshint; run; Specifies to ignore the values listed when determining min and max range

25 SGPLOT – Stacked Bar chart proc sgplot data=sashelp.cars; vbar type/stat=percent group=origin; run;

26 SG Procedure – Grouped Bar chart proc sgplot data=sashelp.cars; vbar type/stat=percent group=origin datalabel groupdisplay=cluster; run; Note: The %’s calculated are out of the total. If you want to show distribution of origin within type, for example, you would need to calculate first.

27 SGPlot – Grouped Bar chart proc freq data=sashelp.cars; tables type*origin; ods output CrossTabFreqs=Pct; run; proc sgplot data=Pct; vbar type/ group=origin groupdisplay=cluster response=RowPercent; yaxis label=“Percent”; run;

28 SGPlot – Axis Table proc sgplot data=Pct; vbar type/ group=origin groupdisplay=cluster response=RowPercent; xaxistable frequency/ title='Frequency'; keylegend /location=inside position=topright noborder; yaxis label=“Percent”; run;

29 Some Notes on Axis Tables Can be used with any kind of plot. For categorized charts the category and group variables from the chart are used automatically. For other plots you would need to specify. – xaxistable variable /x=xvariable class=groupvariable; You can specify more than one variable or include multiple xaxistable commands yaxistable also available

30 SGPLOT – Scatter Plots proc sgplot data=sashelp.class; scatter x=height y=weight/ group=sex; keylegend /location=inside position=topleft down=2; run;

31 SGPLOT – Easily Add Reference Lines proc sgplot data=sashelp.class; refline 100/axis=y; scatter x=height y=weight/ group=sex; keylegend /location=inside position=topleft down=2; run;

32 SGPLOT – Scatter Plots with Error Bars proc sgplot data=class_means; scatter x=sex y=wt_mean/ yerrorlower=wt_lclm yerrorupper=wt_uclm; yaxis label=“Mean Weight”; xaxis offsetmin=0.25 offsetmax=0.25; run;

33 SGPLOT – Series Plots proc sgplot data=sashelp.stocks; series x=date y=close/ group=stock; run; proc sgplot data=sashelp.stocks; series x=date y=close/group=stock curvelabel curvelabelpos=max; run;

34 SGPlot Now let’s create this plot with some of what we’ve learned so far.

35 SGPlot –Overlaying Plots proc sgplot data=sashelp.classfit noautolegend; band x=height upper=uppermean lower=lowermean/name='cl' legendlabel='95% Confidence Limits'; run;

36 SGPlot –Overlaying Plots proc sgplot data=sashelp.classfit noautolegend; band x=height upper=uppermean lower=lowermean/name='cl' legendlabel='95% Confidence Limits'; scatter x=height y=weight; run;

37 SGPlot –Overlaying Plots proc sgplot data=sashelp.classfit noautolegend; band x=height upper=uppermean lower=lowermean/name='cl' legendlabel='95% Confidence Limits'; scatter x=height y=weight; series x=height y=predict/ name='fit'; run;

38 SGPlot –Overlaying Plots proc sgplot data=sashelp.classfit noautolegend; band x=height upper=uppermean lower=lowermean/name='cl' legendlabel='95% Confidence Limits'; scatter x=height y=weight; series x=height y=predict/name='fit'; series x=height y=lower/ lineattrs=(pattern=dash) name='pl' ; series x=height y=upper/ lineattrs=(pattern=dash); run;

39 SGPlot –Overlaying Plots proc sgplot data=sashelp.classfit noautolegend; band x=height upper=uppermean lower=lowermean/name='cl' legendlabel='95% Confidence Limits'; scatter x=height y=weight; series x=height y=predict/name='fit'; series x=height y=lower/ lineattrs=(pattern=dash) name='pl' ; series x=height y=upper/ lineattrs=(pattern=dash); inset "R(*ESC*){sup '2'} = 0.77" "Adjusted R(*ESC*){sup '2'} = 0.76"; run;

40 SGPlot –Overlaying Plots proc sgplot data=sashelp.classfit noautolegend; band x=height upper=uppermean lower=lowermean/name='cl' legendlabel='95% Confidence Limits'; scatter x=height y=weight; series x=height y=predict/name='fit'; series x=height y=lower/ lineattrs=(pattern=dash) name='pl' ; series x=height y=upper/ lineattrs=(pattern=dash); inset "R(*ESC*){sup '2'} = 0.77" "Adjusted R(*ESC*){sup '2'} = 0.76"; keylegend 'fit' 'cl' 'pl'; run;

41 SGPLOT – Or just use the reg plot proc sgplot data=sashelp.class; reg x=height y=weight/cli clm; keylegend /across=3; run;

42 http://support.sas.com/resources/papers/proceedings15/2441-2015.pdf

43 SGPANEL PROCEDURE

44 SGPANEL Procedure Classification panels – Same plot repeated by classification variable SGPLOT syntax carries over with some minor changes – xaxis is now colaxis – yaxis is now rowaxis

45 SGPANEL Procedure proc sgpanel data=cars_reduced; panelby type/novarname; scatter x=mpg_city y=horsepower; run;

46 SGPanel - Layout panelby type/ novarname columns=4; Or panelby type/ novarname layout=columnlattice; panelby type/ novarname rows=4; Or panelby type novarname/ layout=rowlattice;

47 SGPANEL Procedure – 2 Class Variables panelby type origin/ novarname; panelby type origin/ novarname layout=lattice;

48 SGSCATTER PROCEDURE

49 SGSCATTER Procedure Comparative scatter plots or scatter plot matrices Does not use layered architecture Supports 3 plot statements

50 SGScatter – Plot statement proc sgscatter data=sashelp.cars; plot (mpg_city mpg_highway)* horsepower; run;

51 SGScatter – Compare statement proc sgscatter data=sashelp.cars; compare y=(mpg_city mpg_highway) x=horsepower; run;

52 SGScatter – Matrix statement proc sgscatter data=sashelp.cars; matrix mpg_city mpg_highway horsepower enginesize weight length; run;

53 TAKE AWAY MESSAGE

54 Take away message SAS has made many advances in their graphics procedures ODS graphics are easy to use and produce high quality plots There are constant improvements and new features being added For primarily SAS users there is no longer a need to rely on R for generating plots

55 SAS Version All examples presented have been generated using SAS 9.4. Some of the code might not run in 9.2-9.3.

56 Talk Materials All materials will soon be available on SharePoint (waiting for the page to be set up) For now you can find them at my SAS community user page http://www.sascommunity.org/wiki/User:Lopezrhttp://www.sascommunity.org/wiki/User:Lopezr

57 Good Resources Statistical Graphics Procedures by Example: Effective Graphs Using SAS – Sanjay Matange & Dan Heath Graphically Speaking Blog (http://blogs.sas.com/content/graphicallyspeaking/)http://blogs.sas.com/content/graphicallyspeaking/ SAS Tips Sheets – ODS Graphics ODS Graphics – SG Procedures SG Procedures – SGPlot SGPlot – SGPanel SGPanel SAS SG Procedures Documentation

58 FUTURE TALKS

59 Future talks Modifying style attributes Introduction to Graph Template Language (GTL) Automatic ODS Graphics from SAS Procedures and How to Modify These Useful SAS Graphics Macros Step-by-step examples of some plots

60 QUESTIONS?

61 THANKS


Download ppt "Introduction to SAS ODS Graphics September 16, 2015 Rocio Lopez."

Similar presentations


Ads by Google