Introduction to SAS Essentials Mastering SAS for Data Analytics

Slides:



Advertisements
Similar presentations
1 SESSION 5 Graphs for data analysis. 2 Objectives To be able to use STATA to produce exploratory and presentation graphs In particular Bar Charts Histograms.
Advertisements

Summary Statistics/Simple Graphs in SAS/EXCEL/JMP.
Introduction to VistaPHw Charting Function
Introduction to Formatting VistaPHw Charts Brought to you by: The Vista Partnership February 2007.
Step-by-Step: Adjust a Chart Axis USE the Pricing Final presentation that is still open from the previous exercise. 1.Click the chart on slide 2 to select.
Basics of Biostatistics for Health Research Session 2 – February 14 th, 2013 Dr. Scott Patten, Professor of Epidemiology Department of Community Health.
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Copyright © 2010, 2007, 2004 Pearson Education, Inc. All Rights Reserved. Lecture Slides Elementary Statistics Eleventh Edition and the Triola.
PowerPoint Practice Exercise
Introduction to Excel 2007 Part 2: Bar Graphs and Histograms February 5, 2008.
Tinkerplots V Carryn Bellomo
Graphing With Excel 2010 University of Michigan – Dearborn Science Learning Center Based on a presentation by James Golen Revised by Annette Sieg…
GRAPHICAL DESCRIPTIVE STATISTICS FOR QUALITATIVE, TIME SERIES AND RELATIONAL DATA.
Web Page Development Identify elements of a Web Page Start Notepad
Statistics Lecture 2. Last class began Chapter 1 (Section 1.1) Introduced main types of data: Quantitative and Qualitative (or Categorical) Discussed.
Introduction to Excel 2007 Bar Graphs & Histograms Psych 209 February 1st, 2011.
SW318 Social Work Statistics Slide 1 Using SPSS for Graphic Presentation  Various Graphics in SPSS  Pie chart  Bar chart  Histogram  Area chart 
CS1100: Computer Science and Its Applications Creating Graphs and Charts in Excel.
Understanding and Comparing Distributions
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms Psych 209.
The gchart Procedure The gchart Procedure is used to create bar charts of various types (it can also create pie charts. It’s most basic form would look.
11 Chapter 3: Getting Started with Tasks 3.1 Introduction to Tasks and Wizards 3.2 Creating a Frequency Report 3.3 Generating HTML, PDF, and RTF Output.
Introduction to SAS Essentials Mastering SAS for Data Analytics
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
With Microsoft Excel 2007 Comprehensive 1e© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Excel 2007 Comprehensive.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
Introduction to SAS Essentials Mastering SAS for Data Analytics
Creating your own form from scratch.. To create a custom form, you can modify an existing form or design and create a form from scratch. In either case,
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
Getting Started with HTML Please use speaker notes for additional information!
The introduction to SPSS Ⅱ.Tables and Graphs for one variable ---Descriptive Statistics & Graphs.
G053 Lecture 12 Introduction To HTML Mr C Johnston ICT Teacher
Copyright © 2008 SAS Institute Inc. All rights reserved. SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks.
A Picture Is Worth A Thousand Words. DAY 7: EXCEL CHAPTER 4 Tazin Afrin September 10,
Microsoft ® Office Excel 2007 Working with Charts.
Introduction to SAS Essentials Mastering SAS for Data Analytics
WINKS 7 Tutorial 7 – Advanced Topic: Labels and Formats Permission granted for use for instruction and for personal use. © Alan C. Elliott,
Advanced Stata Workshop FHSS Research Support Center.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
Grade 8 Math Project Kate D. & Dannielle C.. Information needed to create the graph: The extremes The median Lower quartile Upper quartile Any outliers.
Lecture 3 Topic - Descriptive Procedures Programs 3-4 LSB 4:1-4.4; 4:9:4:11; 8:1-8:5; 5:1-5.2.
Advanced Graphing Using Excel V.1 Part II: Giving your graph style Written and Created by: James Golen University of Michigan – Dearborn Science Learning.
PROC GPLOT GPLOT is used to make two dimensional scatter-plots. General Syntax: proc gplot data=data-set options; plot y-variable*x-variable/options; run;
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
Mr. Magdi Morsi Statistician Department of Research and Studies, MOH
1 Statistical Software Programming. STAT 6360 –Statistical Software Programming SAS Graphics SAS has two main facilities for producing graphics: 1.ODS.
MATH 2311 Section 1.5. Graphs and Describing Distributions Lets start with an example: Height measurements for a group of people were taken. The results.
Displaying Data  Data: Categorical and Numerical  Dot Plots  Stem and Leaf Plots  Back-to-Back Stem and Leaf Plots  Grouped Frequency Tables  Histograms.
SAS ® is a very powerful tool when producing Graphics. A single graphical data step can easily create a Kaplan Meier Plot, but there is no single graphical.
SAS/GRAPH The Basics. Today’s Topics GOPTIONS GPLOT GCHART GCONTOUR G3D.
Introduction to SAS ODS Graphics September 16, 2015 Rocio Lopez.
Copyright © 2009 Pearson Education, Inc. Slide 4- 1 Practice – Ch4 #26: A meteorologist preparing a talk about global warming compiled a list of weekly.
Graphs with SPSS Aravinda Guntupalli. Bar charts  Bar Charts are used for graphical representation of Nominal and Ordinal data  Height of the bar is.
Academic Computing Services 2007 Microsoft Word 2010 Publishing Long Documents This Guide will teach you how to work with long documents such as dissertations.
SOC 305, Prof. Robert Martin Southeastern Louisiana University.
ODS Graphics By Example March 16, 2016 Rocio Lopez.
Lesson 3 Overview Descriptive Procedures Controlling SAS Output
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.
Laugh, and the world laughs with you. Weep and you weep alone
INTRODUCTION TO SGPLOT Zahir Raihan OVERVIEW  ODS Graphics  SGPLOT overview  Plot Content  High value plot statements  High value plot options 
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Presentation transcript:

Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward

Chapter 18: CREATING CUSTOM GRAPHS PART 2 SAS ESSENTIALS -- Elliott & Woodward

18.4 CREATING STACKED BAR CHARTS Another often-used type of bar chart is a stacked bar chart. To create stacked bar charts do not use the GROUP option. Do Hands On Exercise p 410 (AGRAPH7.SAS) PATTERN1 V=R1 C=RED; * FOR BUS; PATTERN2 V=R1 C=BLUE; * FOR CAR; PATTERN3 V=R1 C=BLACK; * FOR WALK; TITLE C=RED 'Stacked Bars'; PROC GCHART DATA=MYSASLIB.SURVEY; VBAR GENDER / SUBGROUP=ARRIVE WIDTH=15; RUN;QUIT; Note – SUBGROUP but no GROUP option SAS ESSENTIALS -- Elliott & Woodward

Resulting Bar Chart By not including a GROUP option, the bars are stacked rather than each group being a separate bar. SAS ESSENTIALS -- Elliott & Woodward

Make a few changes… Results is a chart in grays… PATTERN1 V=S C=GRAYAA; *FOR BUS(Dark Gray); PATTERN2 V=S C=GRAYCC; *FOR CAR (Medium Gray) ; PATTERN3 V=S C=GRAYEE; *FOR WALK (Light GRAY) ; Results is a chart in grays… SAS ESSENTIALS -- Elliott & Woodward

Put the GROUP Option Into the Code PROC GCHART DATA=MYSASLIB.SURVEY; VBAR GENDER / GROUP=ARRIVE SUBGROUP=GENDER WIDTH=10; RUN;QUIT; Bars not stacked SAS ESSENTIALS -- Elliott & Woodward

Open and Run AGRAPH7A.SAS Put together several of the options/ ideas to make a finished chart… PATTERN1 V=R1 C=RED; * FOR BUS; PATTERN2 V=R2 C=BLUE; * FOR CAR; PATTERN3 V=R3 C=BLACK; * FOR WALK; LEGEND1 ACROSS=1 LABEL=("Gender") POSITION=(top inside left) VALUE=(H=1 'Male' 'Female'); AXIS1 label=(A=90 Color=RED H=2 F="Swiss/Bold" "Count"); TITLE C=RED 'Example Bar Chart'; PROC GCHART DATA=MYSASLIB.SURVEY; VBAR GENDER / GROUP=ARRIVE SUBGROUP=GENDER WIDTH=10 LEGEND=LEGEND1 RAXIS=AXIS1 OUTSIDE=FREQ ; RUN; QUIT; SAS ESSENTIALS -- Elliott & Woodward

Resulting Chart… SAS ESSENTIALS -- Elliott & Woodward

Discussion of the code… (LEGEND) ACROSS=1 LABEL=("Gender") POSITION=(top inside left) VALUE=(H=1 'Male' 'Female'); The LEGEND1 statement creates a key labeled "Gender" that appears at the top, inside left in the graph frame, with the key items "Male" and "Female" listed. The ACROSS option specifies that the key has items listed one across. SAS ESSENTIALS -- Elliott & Woodward

Discussion of the code (AXIS) AXIS1 label=(A=90 Color=RED H=2 F="Swiss/Bold" "Count"); The AXIS1 statement defines an axis to be used as the vertical axis where the name "Count" will be displayed at a 90° angle using the Swiss font, in red, with a height of2 units (default is 1). In the PROC GCHART statements, note the LEGEND = LEGEND1 and RAXIS=AXIS1 statements. These apply the legend and axis to the chart. The statement OUTSIDE=FREQ. This tells the program to display the count (FREQ) outside for each bar. SAS ESSENTIALS -- Elliott & Woodward

18.5 CREATING MEAN BARS USING GCHART An often-used analysis graphic is one that displays means as bars with error bars around the mean indicating a level of variability. Do Hands On Exercise p 412 (AGRAPH8.SAS) SAS ESSENTIALS -- Elliott & Woodward

MEANS will be displayed with 99% CI Errorbars on TOP Code for Means Plot PATTERN1 V=L3 COLOR=LIGHTBLUE; AXIS1 LABEL=(A=90 H=1.5 F="SWISS" "OBSERVATION" C=BLUE); AXIS2 LABEL=(H=1.5 F="SWISS" "GROUP"); TITLE1 'Mean displayed with 95% error bars'; PROC GCHART DATA=MYSASLIB.SOMEDATA; VBAR GP / WIDTH=10 TYPE=MEAN SUMVAR=TIME1 INSIDE=MEAN CLM=99 ERRORBAR=TOP RAXIS=AXIS1 MAXIS=AXIS2 COUTLINE=SAME WOUTLINE=2; RUN; QUIT; Note TYPE=MEAN MEANS will be displayed with 99% CI Errorbars on TOP SAS ESSENTIALS -- Elliott & Woodward

Means Plot Results TYPE=MEAN SUMVAR=TIME1 Results in MEAN of TIME 1 displayed. INSIDE=MEAN CLM=99 ERRORBAR=TOP Results in the error bar on top and the mean in the bar SAS ESSENTIALS -- Elliott & Woodward

Summary of the options used PATTERN1 makes the bars light blue with an L3 pattern. AXIS2 specifies the RAXIS (Response axis), AXIS2 specifies the MAXIS (Midpoint Axis). RAXIS is displayed rotated by 90o and both are displayed with a height of 1.5. SUMVAR=TIME1 tells SAS to use TIME1 to calculate the mean INSIDE=MEAN results in values displayed in the bars. CLM= 99 specifies a 99% confidence interval on the mean. TYPE=MEAN specifies the MEAN statistic used in the ERRORBAR. ERRORBAR=TOP causes the CI error bars to be displayed on top. COUTLINE and WOUTLINE specify a black outline with width 1. SAS ESSENTIALS -- Elliott & Woodward

Make Changes to AXIS Statement AXIS1 LABEL=(A=90 H=l.S F="SWISS" "OBSERVATION" C=BLUE) MAJOR=(COLOR=BLUE HEIGHT=3 WIDTH=2) MINOR=(NUMBER=4 COLOR=RED HEIGHT=l); Observe changes in how the vertical axis is displayed. (Major and Minor axes) SAS ESSENTIALS -- Elliott & Woodward

Try These Changes Change the ERRORBAR specification to BOTH, rerun and observe the changes. Take off the ERRORBAR, TYPE, and CLM Statements and change INSIDE=MEAN to OUTSIDE=FREQ ( ERRORBAR, TYPE, and CLM do not work with FREQ) Rerun and observe the changes. SAS ESSENTIALS -- Elliott & Woodward

18.6 CREATING BOXPLOTS This section provides information on methods for creating and enhancing box plots. A simplified syntax for PROC BOXPLOT is: PROC BOXPLOT <DATA=datasetname>; <Options>; PLOT <depvar*>groupvar(s)</options>; <Statements>; The PLOT statement is required. For example, a typical simple use (group must first be sorted): PROC BOXPLOT DATA=MYDATA; PLOT HEIGHT*GROUP; RUN; SAS ESSENTIALS -- Elliott & Woodward

Example BoxPlot Code 18.10 Common Statements for PROC BOXPLOT PROC BOXPLOT DATA=CARDATA; PLOT HWYMPG*CYLINDERS /CBOXFILL=LIGHTGREEN; RUN; 18.10 Common Statements for PROC BOXPLOT Statement Explanation DATA=dataname Specifies which data set to use. PLOT <depvar*>groupvar(s); Specifies the variables to use in the plot such as PLOT AGE*GROUP; INSET Specifies an inset key similar to those previously described for histograms. ID variables; Specifies variables used to identify observations BY, FORMAT, LABEL, WHERE Statements common to most procedures. SAS ESSENTIALS -- Elliott & Woodward

Specifies outline color for boxes. For example CBOXES=RED. 18.11 Common options the BOXPLOT PLOT Statement (Follows a slash (/) in PLOT Statement) Option Explanation CBOXES=color Specifies outline color for boxes. For example CBOXES=RED. CBOXFILL=color Specifies the fill pattern for boxes. For example CBOXFILL=LIGHTBLUE. NOCHES Species that boxes will be notches. For an explanation for notches, see McGill, Tukey, and Larsen (1978) BOXSTYLE= Specifies the style of the boxplot. Options include SCHEMATIC, SKELETAL (default). SCHEMATIC displays outliers. SKELETAL does not display outliers. (See example that follows for more explanation.) SAS ESSENTIALS -- Elliott & Woodward

Do Hands On Example p 415 (AGRAPH9.SAS) ODS GRAPHCS OFF may be needed if you are using SAS 9.4 or later. ODS GRAPHICS OFF; Title "Distribution of HwyMPG by Cylinders"; * Sort the data on the grouping variable; PROC SORT DATA=MYSASLIB.CARS OUT=CARDATA;BY CYLINDERS; PROC BOXPLOT DATA=CARDATA; PLOT HWYMPG*CYLINDERS /CBOXFILL=LIGHTGREEN; WHERE CYLINDERS GT 1; RUN; BOXPLOT specification in the PLOT statement SAS ESSENTIALS -- Elliott & Woodward

Resulting Plot for PROC BOXPLOT SAS ESSENTIALS -- Elliott & Woodward

Make changes in PLOT Statement PLOT HWYMPG*CYLINDERS/ CBOXFILL=VLIGB CBOXES=BLACK BOXSTYLE=SCHEMATIC NOTCHES; WHERE CYLINDERS GT 1; The SCHEMATIC option causes outliers to be displayed defined as values greater than the absolute value of 1.5*(interquartile range) NOTCHES measure the difference between two medians. If there is no overlap in the corresponding notches for two plots, it indicates a significant difference in the group medians at a .95 CL. SAS ESSENTIALS -- Elliott & Woodward

Add an ID MODEL; statement The ID statement causes identifications to be displayed for outliers SAS ESSENTIALS -- Elliott & Woodward

Add an INSET Statement INSETGROUP MEAN (5.1 ) MIN MAX / HEADER = 'Mean and Extremes'; The INSET statement added MEAN, MIN and MAX in a table above the graph. SAS ESSENTIALS -- Elliott & Woodward

Finished Code for Boxplot Example Title "Distribution of HwyMPG by Cylinders"; PROC SORT DATA=MYSASLIB.CARS OUT=CARDATA;BY CYLINDERS; PROC BOXPLOT DATA=CARDATA; PLOT HWYMPG*CYLINDERS/ CBOXFILL=VLIGB CBOXES=BLACK BOXSTYLE=SCHEMATIC NOTCHES; ID MODEL; INSETGROUP MEAN (5.1) MIN MAX / HEADER = 'Mean and Extremes'; WHERE CYLINDERS GT 1; RUN; SAS ESSENTIALS -- Elliott & Woodward

18.7 GOING DEEPER: CREATING AN INTERACTIVE BAR USING ODS A useful feature of the ODS introduced in Chapter 8 is its ability to create interactive links within graphs in HTML mode. To do this you create a variable that creates a hypertext link, and then you apply that link to a portion of a graph. The following example uses a graph created using the SAS procedure PROC GCHART, where each bar is a link to a report. Do Hands On Example p 418 (AGRAPH10.SAS) SAS ESSENTIALS -- Elliott & Woodward

Begin with a Simple Bar Chart TITLE "Bar Chart"; PROC GCHART DATA=MYSASLIB.SOMEDATA; HBAR GP/ DISCRETE; RUN; QUIT; SAS ESSENTIALS -- Elliott & Woodward

Create a Report for each Group Suppose for each "group," represented by one of the bars on the plot, you want to make available a set of background statistics. You can associate a link for each bar on the graph to a separate Web page. Thus, each bar becomes a Web page link, and when you click on a bar on the graph, you open an HTML page. The code shown in Figure 18.13 creates an HTML file that contains the report (from PROC MEANS} you wish to associate with Group A. Note that the HTML report is saved in the file named GPA.HTM, and that it contains information about GP="A". (Remember that the format to specify the file in ODS HTML is BODY=.) SAS ESSENTIALS -- Elliott & Woodward

Create a Report for Group A ODS HTML BODY="C:\SASDATA\GPA.HTM"; PROC MEANS DATA= "C:\SASDATA\SOMEDATA" MAXDEC=2 N MEAN STD; VAR AGE TIME1-TIME4; WHERE GP="A"; TITLE 'Summary for GROUP A'; RUN; Create similar report for Groups B and C. The HTML type report is stored in the file named GPA.HTM Creates a report for observations in group a (GP=“A”) SAS ESSENTIALS -- Elliott & Woodward

The Report for Group A Do Hands On Example p 419 (AGRAPH11.SAS) SAS ESSENTIALS -- Elliott & Woodward

Code to Create LINK in a Bar Chart HTMLLINK Created here DATA BARCHART;SET MYSASLIB.SOMEDATA; LENGTH HTMLLINK $40; IF GP="A" THEN HTMLLINK='HREF="GPA.HTM"'; IF GP="B" THEN HTMLLINK='HREF="GPB.HTM"'; IF GP="C" THEN HTMLLINK='HREF="GPC.HTM"'; ODS HTML FILE="C:\SASDATA\GCHART.HTM" GPATH=“C:\SASDATA\"; *.......PART 3: CREATE THE GRAPH; PROC GCHART; HBAR GP/ HTML=HTMLLINK; TITLE 'Summary information for each GP.'; RUN; QUIT; HTMLLINK used here SAS ESSENTIALS -- Elliott & Woodward

Explanation of CODE LENGTH HTMLLINK $40; The HTMLLINK variables defines the hyperlink for Group A LENGTH HTMLLINK $40; IF GP="A" THEN HTMLLINK='HREF="GPA.HTM"'; This code Sets up a length for the new variable HTMLLINK (long enough for an internet address) For Group A, assigns a value to HTMLLINK that is the HREF (an internet address or Hyperlink Reference) to the report that contains information about Group A The same is done for Groups B and C HREF means Hyperlink Reference (an “internet” address.) SAS ESSENTIALS -- Elliott & Woodward

Explanation of Code Defines an HTML (internet lnguage) file where the bar chart is saved, plus defines a path (GPATH) to associate with the links. ODS HTML FILE="C:\SASDATA\GCHART.HTM" GPATH=“C:\SASDATA\"; PROC GCHART; HBAR GP/ HTML=HTMLLINK; TITLE 'Summary information for each GP.'; RUN; QUIT; Creates the Bar Chart, and associated the bars to the HTML link named HTMLLINK. SAS ESSENTIALS -- Elliott & Woodward

Run AGRAPH11.SAS Result looks the same as before But click on one of the bars, and a “report” for that bar is displayed. Change the last IF to IF GP="C" THEN HTMLLINK='HREF="http://www.cnn.com"'; Rerun, and click on the C bar to observe results. SAS ESSENTIALS -- Elliott & Woodward

18.8 GOING DEEPER: SGPLOTS Starting with SAS 9.2, a new way of creating high-quality graphs was introduced. These are called Statistical Graphics Procedures. These include SGPLOT, SGSCATTER, and SGPANEL. We'll illustrate the use of SGPLOT in this section. An advantage of these "SG“ plots is that they can easily be created in standard graphical file types such as JPG (JPEG) or TIF. The basic syntax for SGPLOT is PROC SGPLOT <DATA=dataname> plotstatements/options; SAS ESSENTIALS -- Elliott & Woodward

SGPLOT Syntax At least one plot type statement is required. For example, PROC SGPLOT; HISTOGRAM AGE; RUN; To add a density plot (default is a normal plot), you simply add another plot statement: DENSITY AGE; SAS ESSENTIALS -- Elliott & Woodward

Table 18.13 Common Plot Statements for PROC SGPLOT Plot Statement Explanation HBAR vname or VBAR vname Specifies horizontal or vertical bar chart. For example: HBAR AGE; HISTOGRAM vname Specifies histogram. For example: HISTOGRAM AGE; SCATTERPLOT Specifies scatterplot. SCATTER X=AGE Y=SBP; DENISTY vname Displays density plot. For example DENSITY AGE </TYPE=Kernel or Normal) KEYLEGEND/options; LOCATION= location of legend (INSIDE or OUTSIDE) POSITION (topleft , topright, bottomleft, bottomright) XAXIS options; and YAXIS options; Options include LABEL=’Label name’, MAX=, MIN=, VALUES=(Min to Max by interval), and OFFSETMIN= OFFSETMAX= (from 0 to 1) REG X=xvar Y=yvar/options Specify regression line for scatterplot where options include ALPHA=, CLI and CLM and GROUP=. SAS ESSENTIALS -- Elliott & Woodward

Do Hands On Exercise p 422 (SGPLOT1.SAS) PROC SGPLOT DATA=MYSASLIB.WOUND; HISTOGRAM SBP; TITLE "SGPLOT Histogram"; RUN; SAS ESSENTIALS -- Elliott & Woodward

Add this code (after HISTOGRAM line) DENSITY SBP/TYPE=KERNEL; SAS ESSENTIALS -- Elliott & Woodward

Add this code DENSITY SBP/TYPE=NORMAL; SAS ESSENTIALS -- Elliott & Woodward

Include multiple plots – they overlay one another. Final Code PROC SGPLOT DATA=MYSASLIB.WOUND; HISTOGRAM SBP; DENSITY SBP/TYPE=KERNEL; DENSITY SBP/TYPE=NORMAL; TITLE "SGPLOT Histogram"; RUN; Include multiple plots – they overlay one another. SAS ESSENTIALS -- Elliott & Woodward

Creating an SGPLOT BAR CHART Do Hands On Exercise p 423 (SGPLOT2.SAS) PROC SGPLOT DATA=MYSASLIB.WOUND; HBAR RACE_CAT; TITLE "SGPLOT Bar Chart"; RUN; SAS ESSENTIALS -- Elliott & Woodward

Make Changes Change to VBAR RACE_CAT/GROUP=GENDER; SAS ESSENTIALS -- Elliott & Woodward

Add more code…(after the GROUP=GENDER; line) KEYLEGEND / LOCATION=INSIDE POSITION=TOPLEFT; XAXIS LABEL="Race“; Notice Notice SAS ESSENTIALS -- Elliott & Woodward

Creating a scatterplot Using SGPLOT PROC SGPLOT DATA =sasfilename; SCATTER X=varnamel Y=varname2; RUN; An option that is helpful for the SCATTER plot type is MARKERATTRS= (specifications) . This option allows you to specify the type of symbol displayed at each point, along with size and color. For example, MARKERATTRS=(symbol=trianglefilled size=lOpx color=red); Do Hands On Example p 425 (SGPLOT3.SAS) SAS ESSENTIALS -- Elliott & Woodward

Scatterplot Example PROC SGPLOT DATA =ANCOVA; SCATTER X=PRETEST Y=POSTTEST; RUN; SAS ESSENTIALS -- Elliott & Woodward

Change code (add /GROUP=METHOD) SCATTER X=PRETEST Y=POSTTEST/GROUP=METHOD; Dots are two different colors according to group. SAS ESSENTIALS -- Elliott & Woodward

Change the shape and size of the “dot” to a filled triangle. Change code to SCATTER X=PRETEST Y=POSTTEST/GROUP=METHOD MARKERATTRS=(symbol=trianglefilled size=10px); Change the shape and size of the “dot” to a filled triangle. SAS ESSENTIALS -- Elliott & Woodward

Add these lines (before the RUN;) KEYLEGEND / LOCATION=INSIDE POSITION=TOPLEFT; XAXIS LABEL="Pre Test Results"; YAXIS LABEL="Post Test Results"; Legend added SAS ESSENTIALS -- Elliott & Woodward

Add this line (before RUN statement) REG X=PRETEST Y=POSTTEST/ GROUP=METHOD; Adds regression lines by group SAS ESSENTIALS -- Elliott & Woodward

Final Code for Scatterplot with Regression Lines PROC SGPLOT DATA =ANCOVA; SCATTER X=PRETEST Y=POSTTEST/GROUP=METHOD MARKERATTRS=(symbol=trianglefilled size=10px); KEYLEGEND / LOCATION=INSIDE POSITION=TOPLEFT; XAXIS LABEL="Pre Test Results"; YAXIS LABEL="Post Test Results"; REG X=PRETEST Y=POSTTEST/ GROUP=METHOD; RUN; SAS ESSENTIALS -- Elliott & Woodward

Using SGPLOT to create a Bubble Plot Do Hands on Exercise p 427 (SGPLOT4.SAS) PROC SGPLOT DATA=MYSASLIB.CORONARY; TITLE 'BUBBLE PLOT'; TITLE2 'Bubble is BMI'; BUBBLE X=AGE Y=SBP SIZE=BMI / TRANSPARENCY=0.5; YAXIS GRID; RUN; Determines size of bubble Determines transparency of bubble. SAS ESSENTIALS -- Elliott & Woodward

Results of Bubble Plot SAS ESSENTIALS -- Elliott & Woodward

Continue Exercise… Change the TRANSPARENCY to 0.9 and run the code. Change it to 0.1 and run the code. Change the transparency back to 0.5. Add the option GROUP=INSURANCE after the TRANSPARENCY statement (and before the semicolon). Rerun and note the different colors by group. Change the option in the BUBBLE statement to /TRANSPARANCY=O.5 FILLATTRS=(COLORS=GREEN) to change the color of the bubbles to green. SAS ESSENTIALS -- Elliott & Woodward

18.9 OTHER WAYS TO CUSTOMIZE PLOTS There are at least two other techniques you can use to customize plots: (1) Annotation Data Sets and (2) Graph Template Language (GTL): Annotation Data Set – a data set that contains graphic commands that you then apply to an existing plot (or create an entirely custom plot GTL - is a SAS sub-language used to specify the details of how an ODS graph is created Both of these techniques are beyond the scope of this book. (See SAS Documentation for more information.) SAS ESSENTIALS -- Elliott & Woodward

18.10 SUMMARY This chapter described a small portion of the many graphical options available in SAS. However, the discussion of graphs in this chapter (and elsewhere in the book) covered many of the common graphs used in data analysis. Continue to Chapter 19: CREATING CUSTOM REPORTS SAS ESSENTIALS -- Elliott & Woodward

These slides are based on the book: Introduction to SAS Essentials Mastering SAS for Data Analytics, 2nd Edition By Alan C, Elliott and Wayne A. Woodward Paperback: 512 pages Publisher: Wiley; 2 edition (August 3, 2015) Language: English ISBN-10: 111904216X ISBN-13: 978-1119042167 These slides are provided for you to use to teach SAS using this book. Feel free to modify them for your own needs. Please send comments about errors in the slides (or suggestions for improvements) to acelliott@smu.edu. Thanks. SAS ESSENTIALS -- Elliott & Woodward