sas slides 9 : plots and graphs

25
SASTechies [email protected] http://www.sastechies.com

Upload: sastechies

Post on 17-Nov-2014

4.267 views

Category:

Documents


4 download

DESCRIPTION

Learning Base SAS,Advanced SAS,Proc SQl, ODS, SAS in financial industry,Clinical trials, SAS Macros,SAS BI,SAS on Unix,SAS on Mainframe,SAS interview Questions and Answers,SAS Tips and Techniques,SAS Resources,SAS Certification questions...visit http://sastechies.blogspot.com

TRANSCRIPT

Page 1: SAS Slides 9 : Plots and Graphs

[email protected]

http://www.sastechies.com

Page 2: SAS Slides 9 : Plots and Graphs

Creating

◦ SAS Tables, ◦ Listings, ◦ Basic Statistics Procedures with SAS ◦ Graphs◦ ODS HTML◦ Proc Report and Other Utility Procedures

04/08/23SAS Techies 2009 2

TLG’s

Page 3: SAS Slides 9 : Plots and Graphs

proc format; value $repfmt 'TFB'='Bynum'

'MDC'='Crowley' 'WKK'='King'; value cntyfmt 12='Durham'

45='Wake' 13='Orange';run;

proc print data=vcrsales; var salesrep county unitsold;format salesrep $repfmt. County

cntyfmt.; run;

04/08/23SAS Techies 2009 3

Page 4: SAS Slides 9 : Plots and Graphs

title1 'Heart Rates for Patients with'; title3 'Increased Stress Tolerance Levels';

In SAS listing output, title line 2 appears blank

In HTML output, title lines simply appear consecutively, without extra spacing to indicate skipped title numbers.

TITLE<n> 'title-text';    where n is a number from 1 to 10

that specifies the title line, and 'title-text' is the actual title to be displayed.

The maximum title length depends on your operating environment and the value of the linesize=option

Title statement is global and additive

Cancelling titlesA TITLE statement remains in effect

until you modify it, cancel it, or end your SAS session.

Redefining a title line cancels any higher-numbered title lines.

To cancel all previous titles, specify a null TITLE statement

04/08/23SAS Techies 2009 4

Heart Rates for Patients with

Increased Stress Tolerance Levels

Obs RestHR MaxHR RecHR

2 68 171 133

3 78 177 139

8 70 167 122

11 65 181 141

14 74 152 113

15 75 158 108

20 78 189 138

Page 5: SAS Slides 9 : Plots and Graphs

FOOTNOTE<n> 'footnote-text';     where n is a number from 1 to 10 that specifies the footnote line, and footnote-text is the actual footnote to be displayed.

The maximum footnote length depends on your operating environment and the value of the LINESIZE= option.

Be sure to match quotation marks that enclose the footnote text.

Footnote statement is global and additive

04/08/23SAS Techies 2009 5

Obs RestHR MaxHR RecHR

2 68 171 133

3 78 177 139

8 70 167 122

11 65 181 141

14 74 152 113

15 75 158 108

20 78 189 138

Data from Treadmill Tests

1st Quarter Admissions

Page 6: SAS Slides 9 : Plots and Graphs

how to create single plots and overlaid plots, then refine the plots by scaling axes, defining plotting symbols, and specifying methods of interpolating plotted points.

GPLOT procedure PROC GPLOT DATA=SAS-data-set;

        PLOT vertical-variable*horizontal-variable;RUN;

04/08/23SAS Techies 2009 6

Page 7: SAS Slides 9 : Plots and Graphs

proc gplot data=clinic.totals2000; plot newadmit*month; run;

PLOT vertical-variable*horizontal-variable /            VAXIS=<value-list | range>           HAXIS=<value-list | range>;

Ex. vaxis=10 to 100 by 10

04/08/23SAS Techies 2009 7

Page 8: SAS Slides 9 : Plots and Graphs

PLOT vertical-variable-1*horizontal-variable           vertical-variable-2*horizontal-variable /  OVERLAY;

If the OVERLAY option were not specified, each plot request would generate a separate graph

SYMBOL statement is used to enhance your plots by specifying plotting symbols, plot lines, color, and interpolation.

Interpolation is a technique for estimating values between plot points and drawing lines to connect the points.

04/08/23SAS Techies 2009 8

proc gplot data=clinic.totals2000; plot therapy*month treadmill*month / overlay; run; |<--pair1-->| |<---pair2--->|

Page 9: SAS Slides 9 : Plots and Graphs

symbol1 color=red value=star interpol=spline height=1 cm width=4; proc gplot data=clinic.totals2000;

plot therapy*month; run;

04/08/23SAS Techies 2009 9

 VALUE=  plotting symbol

 HEIGHT=  height of the plotting symbol

 INTERPOL=  

 interpolation technique

 WIDTH=  thickness of the line in pixels

 COLOR=  color of plotting symbols or lines 

symbol1 color=red value=star interpol=spline height=1 cm width=4; symbol2 color=green value=plus interpol=spline height=1 cm width=4;

Page 10: SAS Slides 9 : Plots and Graphs

Setting Plotting Symbols The VALUE= (or V=) option specifies the plotting symbol that represents each data point. Possible values for the VALUE= option include

the letters A through W the numbers 0 through 9 a number of special

symbols including PLUS, STAR, SQUARE, DIAMOND, TRIANGLE, and many others

NONE, which produces a plot with no symbols for data points.

04/08/23SAS Techies 2009 10

Page 11: SAS Slides 9 : Plots and Graphs

Setting Plotting Symbol Height You can use the HEIGHT= (or H=) option to specify the height of the plotting symbol. You can specify a value for height and a unit of measurement. Valid units are

percentage of the display area (PCT)

inches (IN) centimeters (CM) points (PT) character cells (CELL),

which is the default unit.

04/08/23SAS Techies 2009 11

symbol1 value=triangle height=1 cm color=black;

Page 12: SAS Slides 9 : Plots and Graphs

symbol1 value=triangle interpol=none; Specifying Connecting Lines To specify whether or not to connect plotted points, you use the INTERPOL= (or I=) option in the SYMBOL statement. Connecting lines can be straight lines, smoothed lines, or vertical lines drawn from plotted points to a horizontal line at zero or the minimum value on the Y axis.

Possible values include NONE, JOIN, NEEDLE, SPLINE, HILO, STD, and more.

04/08/23SAS Techies 2009 12

Page 13: SAS Slides 9 : Plots and Graphs

 SYMBOL statements are both global and additive. This means that

once defined, they remain in effect until you change/cancel/or end the SAS session

within one SYMBOL statement, you can change the value of one option value without affecting the values of other options.

Ex: symbol1 value=square color=blue interpol=needle; symbol1 v=triangle;

04/08/23SAS Techies 2009 13

Page 14: SAS Slides 9 : Plots and Graphs

Canceling SYMBOL Statement Options an individual option

symbol1 interpol=join color=yellow width=1.5; symbol1 color=;

all options in one SYMBOL statement symbol1 interpol=join color=yellow width=2 value=square; symbol2 interpol=join color=blue width=2 value=star; symbol2; - Submitting the null SYMBOL2 statement cancels the SYMBOL2 statement but does not affect higher or lower numbered SYMBOL statements.

all SYMBOL statements currently in effect. cancel all SYMBOL statements in effect by submitting statement: goptions reset=symbol;

When you cancel a SYMBOL statement option, you return the option to its default value.

04/08/23SAS Techies 2009 14

Page 15: SAS Slides 9 : Plots and Graphs

symbol1 value=triangle interpol=none color=red; proc gplot data=clinic.totals2000;

plot newadmit*month; run; quit; To end the procedure,

you must submit another PROC step, a DATA step, or a QUIT statement (shown below). quit;

Not all procedures support RUN-group processing, and implementation varies.

04/08/23SAS Techies 2009 15

Page 16: SAS Slides 9 : Plots and Graphs

04/08/23SAS Techies 2009 16

symbol1 interpol=spline value=none color=red; symbol2 interpol=spline value=none color=blue; proc gplot data=clinic.therapy1999; plot swim*month aerclass*month/overlay; where swim>35 and aerclass>35; run;

Page 17: SAS Slides 9 : Plots and Graphs

proc gplot data=air.airqual; plot avgtsp*month=state / vminor=3 hminor=0 areas=2 nolegend; pattern1 color=red; pattern2 color=blue; note move=(10, 19) color=red 'Alabama';note move=(10, 20) color=blue

'California'; symbol1 c=red i=spline v=none; symbol2 c=blue i=spline

v=none; where state in ("CA" , "AL"); quit;

04/08/23SAS Techies 2009 17

Page 18: SAS Slides 9 : Plots and Graphs

PROC GCHART <DATA=SAS-data-set>;        chart-form chart-variable </ options>;RUN;

SAS-data-set is the name of the SAS data set to be used.

chart-form is HBAR, HBAR3D, VBAR, VBAR3D, PIE, or PIE3D. The chart-form specifies a 2D or 3D horizontal bar chart, vertical bar chart, or pie chart, respectively.

chart-variable is the variable that determines the number of bars or pie slices.

The default statistic for GCHART is FREQ (frequency).

04/08/23SAS Techies 2009 18

Page 19: SAS Slides 9 : Plots and Graphs

proc gchart data=clinic.insure;

hbar company;

run; PROC GCHART <DATA=SAS-data-set>;        chart-form chart-variable / TYPE=statistic;RUN; QUIT;

Statistics includeCFREQ (cumulative frequency), PERCENT (percent), and CPERCENT (cumulative percent).

For horizontal bar charts, unless otherwise specified, PROC GCHART also displays the statistics CFREQ PERCENT, and CPERCENT

CFREQ  and CPERCENT  are NOT available for pie charts.

04/08/23SAS Techies 2009 19

Page 20: SAS Slides 9 : Plots and Graphs

proc gchart data=clinic.insure; vbar company / sumvar=balancedue; run;

SUMVAR= option to summarize a variable within categories.

When you specify SUMVAR=, the default statistic is SUM, so the chart displays the total of the values of the summary variable for each unique value of the chart variable.

When you use SUMVAR=,

you can also use TYPE=. However, the value of TYPE= can be only SUM or MEAN.

04/08/23SAS Techies 2009 20

proc gchart data=clinic.insure; vbar company / sumvar=balancedue type=mean;

Page 21: SAS Slides 9 : Plots and Graphs

proc gchart data=clinic.insure; vbar company /

sumvar=balancedue type=mean patternid=midpoint; run;

enhance your charts by specifying patterns other than the default values for bars or slices.

PATTERNID=<BY | MIDPOINT | GROUP | SUBGROUP> where BY, MIDPOINT, GROUP, or SUBGROUP specify that bar colors and/or patterns vary according to the option specified.

You cannot use the PATTERNID=MIDPOINT option when you create pie charts.

04/08/23SAS Techies 2009 21

Page 22: SAS Slides 9 : Plots and Graphs

proc gchart data=clinic.admit; hbar sex / sumvar=weight type=mean group=actlevel patternid=group; run;

pattern1 color=lib; pattern2 color=lig; proc gchart data=clinic.admit; hbar age / sumvar=weight type=mean

subgroup=sexpatternid=subgroup

mean; run;

04/08/23SAS Techies 2009 22

Page 23: SAS Slides 9 : Plots and Graphs

pie company / sumvar=balancedue type=mean fill=x;

FILL=<X|S> where X changes the fill

pattern for all slices to hatch

S changes the fill pattern for all slices to solid.

You cannot use the FILL= option with bar charts.

04/08/23SAS Techies 2009 23

Page 24: SAS Slides 9 : Plots and Graphs

proc gchart data=clinic.insure; pie3d company / sumvar=balancedue type=mean ctext=blue explode="ACME";where Company in ("ACME", "RURITAN", "USA INC."); run;

pattern1 color=lib; pattern2 color=lig; proc gchart data=clinic.admit; hbar3d age / sumvar=weight

type=mean subgroup=sex patternid=subgroup mean; run;

04/08/23SAS Techies 2009 24

Page 25: SAS Slides 9 : Plots and Graphs

To save graphs in a SAS catalog other than the default catalog, you use the GOUT= option in the PROC statement for the step that creates your graph. So, when you create charts, you specify GOUT= in the PROC GCHART statement.

Ex:symbol1 interpol=spline value=none color=red; symbol2 interpol=spline value=none color=blue; proc gchart data=clinic.therapy1999 gout=newcat; vbar month / sumvar=swim type=sum; hbar month / sumvar=aerclass type=sum; where swim>35 and aerclass>35; run;

04/08/23SAS Techies 2009 25