140 likes | 266 Views
EPIB 698C Lecture 5. 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' ;
E N D
EPIB 698C Lecture 5 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.