Você está na página 1de 25

SASTechies

info@sastechies.com
http://www.sastechies.com
 Creating

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

SAS Techies 2009 11/13/09 2


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;

SAS Techies 2009 11/13/09 3


title1 'Heart Rates for Patients with'; TITLE<n> 'title-text';   
title3 'Increased Stress Tolerance Levels';
where n is a number from 1 to 10
that specifies the title line, and
In SAS listing output, title line 2 appears blank
'title-text' is the actual title to be
displayed.
In HTML output, title lines simply appear
consecutively, without extra spacing to The maximum title length depends on
indicate skipped title numbers. your operating environment and the
value of the linesize=option

Title statement is global and


additive
Heart Rates for Patients with
Increased Stress Tolerance Levels Cancelling titles
Obs RestHR MaxHR RecHR A TITLE statement remains in effect
until you modify it, cancel it, or end
2 68 171 133 your SAS session.
3 78 177 139 Redefining a title line cancels any
8 70 167 122 higher-numbered title lines.
11 65 181 141 To cancel all previous titles, specify a
null TITLE statement
14 74 152 113
15 75 158 108
20 78 189 138

SAS Techies 2009 11/13/09 4


FOOTNOTE<n> 'footnote-text';    
where n is a number from 1 to 10
that specifies the footnote line,
and footnote-text is the actual
Obs RestHR MaxHR RecHR
footnote to be displayed.
2 68 171 133
The maximum footnote length
3 78 177 139
depends on your operating
8 70 167 122
environment and the value of the
11 65 181 141 LINESIZE= option.
14 74 152 113
Be sure to match quotation marks
15 75 158 108 that enclose the footnote text.
20 78 189 138

Data from Treadmill Tests Footnote statement is global


and additive
1st Quarter Admissions

SAS Techies 2009 11/13/09 5


 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;

SAS Techies 2009 11/13/09 6


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

PLOT vertical-
variable*horizontal-variable /
           VAXIS=<value-list |
range>
           HAXIS=<value-list |
range>;
Ex. vaxis=10 to 100 by 10

SAS Techies 2009 11/13/09 7


PLOT vertical-variable-1*horizontal-
variable
           vertical-variable-2*horizontal-
proc gplot data=clinic.totals2000; variable /  OVERLAY;
plot therapy*month treadmill*month /
If the OVERLAY option were not specified,
overlay; each plot request would generate a
run; |<--pair1-->| |<---pair2--->| 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.

SAS Techies 2009 11/13/09 8


 symbol1 color=red value=star
interpol=spline height=1 cm VALUE= plotting symbol
width=4; proc gplot HEIGHT= height of the plotting symbol
data=clinic.totals2000;
plot therapy*month; run; 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;

SAS Techies 2009 11/13/09 9


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.

SAS Techies 2009 11/13/09 10


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)
symbol1 value=triangle height=1 cm color=black;  points (PT)
 character cells (CELL),
which is the default unit.

SAS Techies 2009 11/13/09 11


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.

SAS Techies 2009 11/13/09 12


 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;

SAS Techies 2009 11/13/09 13


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.

SAS Techies 2009 11/13/09 14


 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.

SAS Techies 2009 11/13/09 15


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;

SAS Techies 2009 11/13/09 16


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;

SAS Techies 2009 11/13/09 17


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

SAS Techies 2009 11/13/09 18


proc gchart data=clinic.insure;
hbar company;
run;  PROC GCHART <DATA=SAS-
data-set>;
        chart-form chart-variable /
TYPE=statistic;
RUN; QUIT;

 Statistics include
CFREQ (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.

SAS Techies 2009 11/13/09 19


 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.
proc gchart data=clinic.insure; 
vbar company / sumvar=balancedue type=mean;  When you use SUMVAR=,
you can also use TYPE=.
However, the value of
TYPE= can be only SUM or
MEAN.

SAS Techies 2009 11/13/09 20


proc gchart data=clinic.insure;  enhance your charts by
vbar company / specifying patterns
sumvar=balancedue other than the default
type=mean
patternid=midpoint; run; 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.

SAS Techies 2009 11/13/09 21


 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=sex
patternid=subgroup
mean; run;

SAS Techies 2009 11/13/09 22


 pie company /
sumvar=balancedue  FILL=<X|S> where
type=mean fill=x; 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.

SAS Techies 2009 11/13/09 23


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;

SAS Techies 2009 11/13/09 24


 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;

SAS Techies 2009 11/13/09 25