160 likes | 168 Views
Learn to create bar charts & scatter plots analyzing blood types using PROC GCHART & PROC GPLOT in SAS. Explore syntax, options, and examples for effective data visualization. Master Excel reporting with PROC EXPORT and ExcelXP tagset.
E N D
EPIB 698C Lecture 8 Raul Cruz-Cano
Outline • Procedure syntax • PROC GCHART • PROC GPLOT • Examples
Proc GCHART for bar charts • Example: A bar chart showing the distribution of blood types from the Blood data set DATA blood; INFILE ‘C:\blood.txt'; INPUT ID Sex $ BloodType $ AgeGroup $ X1 X2 X3; run; title"Distribution of Blood Types"; procgchartdata=blood; vbar BloodType; run; quit;
Proc GCHART for bar charts • VBAR: request a vertical bar chart for the variable • Alternatives to VBAR are as follows: HBAR: horizontal bar chart VBAR3D: three-dimensional vertical bar chart HBAR3D: three-dimensional horizontal bar chart PIE: pie chart PIE3D: three-dimensional pie chart DONUT: donut chart
A Few Options procgchartdata=blood; vbar bloodtype/space=0type=percent ; run; quit; Controls spacing between bars Changes the statistic from frequency to percent
Type option • Type =freq : displays frequencies of a categorical variable • Type =pct (Percent): displays percent of a categorical variable • Type =cfreq : displays cumulative frequencies of a categorical variable • Type =cpct (cPercent): displays cumulative percent of a categorical variable
Basic Output This value of 7,000 corresponds to a class ranging from 6500 to 7500 (with a frequency of about 350) SAS computes midpoints of each bar automatically. You can change it by supplying your own midpoints: vbar RBC / midpoints=4000 to 11000 by 1000;
Creating charts with values representing categories • SAS places continuous variables into groups before generating a frequency bar chart • If you want to treat the values as discrete categories, you can use DISCRETE option • Example: create bar chart showing the frequencies by day of the week for the visit to a hospital
libname d “C:\”; dataday_of_week; set d.hosp; Day = weekday(AdmitDate); run; *Program Demonstrating the DISCRETE option of PROC GCHART; title "Visits by Month of the Year"; proc gchart data=day_of_week; vbar Day / discrete; run; quit;
The Discrete Option procgchartdata= day_of_week; vbar day /discrete; run; quit; Discrete establishes each distinct value of the midpoint variable as a midpoint on the graph. If the variable is formatted, the formatted values are used for the construction. If you use discrete with a numeric variable you should: 1. Be sure it has only a few distinct values. or 2. Use a format to make categories for it.
GPLOT • The GPLOT procedure plots the values of two or more variables on a set of coordinate axes (X and Y). • The procedure produces a variety of two-dimensional graphs including • simple scatter plots • overlay plots in which multiple sets of data points display on one set of axes
Procedure Syntax: PROC GPLOT • PROC GPLOT; PLOT y*x </option(s)>; run; • Example: plot of systolic blood pressure (SBP) by diastolic blood pressure (DBP) title"Scatter Plot of SBP by DBP"; procgplotdata=d.clinic; plot SBP * DBP; run;
*controlling the axis ranges; title"Scatter Plot of SBP by DBP"; procgplotdata=d.clinic; plot SBP * DBP / haxis=70 to 120 by 5 vaxis=100 to 220 by 10; run;
Multiple plots can be made in 3 ways: • proc gplot; plot y1*x y2*x /overlay; run; plots y1 versus x and y2 versus x using the same horizontal and vertical axes. (2) proc gplot; plot y1*x; plot2 y2*x; run; plots y1 versus x and y2 versus x using different vertical axes. The second vertical axes appears on the right hand side of the graph. (3) proc gplot ; plot y1*x=z; run; uses z as a classification variable and will produce a single graph plotting y1 against x for each value of the variable z.
Creating Excel Report • There are several options: • PROC EXPORT : • It’s the same as the point and click method but you can do it with code. • LIBNAME ENGINE • LIBNAME engine is one of the newest methods to transfer information from SAS into Excel. • Lets you use Excel as a SAS library. • LIBNAME engine allows advanced customization of your output. It does not give full control of Excel • Excel does not need to be installed on the machine running SAS. • EXCELXP TAGSET: • ExcelXP tagset is an ODS (Output Delivery System) destination available in SAS version 9.1 that utilizes the Extensible Markup Language (XML). • It can be downloaded from the SAS website. • Using the ExcelXP Tagset is a powerful method to control formatting of a spreadsheet. • ExcelXP tagset can be used to export the results of PROC REPORT, PROC TABULATE, or PROC PRINT. It can display multiple tables per worksheet as well as multiple worksheets.
Creating Excel Report DATA style; INFILE‘C:\style.txt'; INPUT Name $ 1-21 style $ 23-40 Origin $ 42; RUN; ods tagsets.excelxp file="C:\comparision.xls"style=statistical options( sheet_interval='none' suppress_bylines='n’); PROCPRINTDATA = style; WHERE style = 'Impressionism'; TITLE'Major Impressionist Painters'; FOOTNOTE'F = France N = Netherlands U = US'; RUN; ods tagsets.excelxp close;