epib 698c lecture 5 raul cruz-cano. outline procedure syntax –proc gchart –proc gplot examples

20
EPIB 698C Lecture 5 Raul Cruz-Cano

Upload: linda-burke

Post on 01-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

EPIB 698C Lecture 5

Raul Cruz-Cano

Page 2: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

Outline

• Procedure syntax– PROC GCHART– PROC GPLOT

• Examples

Page 3: 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 $ RBC WBC chol;run;

title "Distribution of Blood Types";

proc gchart data=blood; vbar BloodType;

run;quit;

Page 4: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

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

Page 5: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

A Few Options

proc gchart data=blood;

vbar bloodtype/space=0 type=percent ;

run;

quit;

Controls spacing between bars

Changes the statistic from frequencyto percent

Page 6: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

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

Page 7: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

Basic Output

This value of 7,000corresponds to a

class ranging from6500 to 7500

(with a frequencyof 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;

Page 8: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

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

Page 9: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

libname d “C:\”;

data day_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;

Page 10: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

The Discrete Option

proc gchart data= day_of_week;

vbar day /discrete;

run;

quit;

Discrete establishes each distinctvalue of the midpoint variable asa midpoint on the graph. If the

variable is formatted, the formattedvalues are used for the construction.

If you use discrete witha numeric variable you

should:1. Be sure it has only a

few distinct values.or

2. Use a format to makecategories for it.

Page 11: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

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

Page 12: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

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";proc gplot data=d.clinic;

plot SBP * DBP;run;

Page 13: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

*controlling the axis ranges;

title "Scatter Plot of SBP by DBP";

proc gplot data=d.clinic;

plot SBP * DBP / haxis=70 to 120 by 5

vaxis=100 to 220 by 10;

run;

Page 14: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

• Multiple plots can be made in 3 ways:

(1)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.

Page 15: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

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.

Page 16: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

SAS ODS(Output Delivery System)

Page 17: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

ODS Purpose

• ODS is a powerful tool that can enhance the efficiency of statistical reporting and meet the needs of the investigator.

• To create output objects that can be send to destinations such as HTML, PDF, RTF (rich text format), or SAS data sets.

• To eliminate the need for macros that used to convert standard SAS output to a Microsoft Word, or HTML document

Page 18: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

ODS RTF Output(rich text file)

ods rtf file='C:\old_computer\teaching\EPIB698A\freq.rtf';

proc freq data=blood;

Table GENDER;

RUN;

ods rtf close; Rft file

Page 19: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

ODS RTF Output(rich text file)

ods rtf file='C:\old_computer\teaching\EPIB698A\freq.rtf ';

proc freq data=blood;

Table GENDER;

RUN;

ods rtf close;

directory File name

Page 20: EPIB 698C Lecture 5 Raul Cruz-Cano. Outline Procedure syntax –PROC GCHART –PROC GPLOT Examples

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’);

PROC PRINT DATA = style;WHERE style = 'Impressionism';TITLE 'Major Impressionist Painters';FOOTNOTE 'F = France N = Netherlands U = US';

RUN;ods tagsets.excelxp close;