Sie sind auf Seite 1von 24

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/02/21 2


 Descriptive
 Distributive

SAS Techies 2009 11/02/21 3


PROC TABULATE creates customized one-, two-, and three-dimensional tables that
display any of a large number of descriptive statistics.
◦ modify virtually every feature of a table
◦ calculate percentages
◦ produce sub-reports without sorting data
◦ summarize data and produce a report in one step
◦ generate multiple tables in one step.
ActLevel LOW ActLevel HIGH
Height Weight
  Height Weight
proc tabulate data=clinic.admit; Min Min  
class sex; Min Min
var height weight; Sex Sex
table sex,height*min weight*min; F 66.00 140.00
run; F 61.00 118.00
M 72.00 168.00 M 71.00 154.00
Height Weight
 
Min Min proc tabulate data=clinic.admit;
proc tabulate data=diabstat; class sex actlevel;
Sex
class type; var height weight;
var premium; F 61.00 118.00 table actlevel,sex,height*min weight*min;
table type premium; run;
M 69.00 147.00
run;

SAS Techies 2009 11/02/21 4


 To set up a table with PROC TABULATE, you need to identify the data you are
analyzing, and then determine
◦ which variables, if any, you need to classify your data
◦ which variables, if any, you need to analyze your data
◦ the type of table you need to represent your data.

PROC TABULATE invokes the procedure and identifies


your data set
CLASS specifies variables used to classify
data
VAR analyze data - uses variables and
statistics to form the table.
TABLE defines the table to display your data
--uses variables and statistics to form
the table.

SAS Techies 2009 11/02/21 5


 Class variables  Analysis Variables Unlike class
◦ can be character or numeric. variables, analysis variables
◦ classify data into groups or ◦ must be numeric
categories. ◦ are used for arithmetic analysis
◦ have only a few distinct values, ◦ often contain continuous values.
in most cases. (PROC TABULATE
prints each value of a class
variable.)

the same variable cannot appear in both the CLASS statement


and the VAR statement in the same step.

SAS Techies 2009 11/02/21 6


 
You use the TABLE statement to specify
• the number of dimensions in the table (page, row,
column)
• the variables in the table (Sex, Height)
• the statistics to be calculated (MAX)                          

    

SAS Techies 2009 11/02/21 7


TABLE page-expression, row-expression, column-expression;

Dimension expressions contain elements.

                                                                                             
Dimension expressions can also contain operators that you use when
combining elements to produce the table you want.

                                                                                         
Commas, one type of operator, separate the dimensions of the table.

                                                                                                                             
    
SAS Techies 2009 11/02/21 8
Type proc tabulate data=clinic.diabstat;
Type
I II I II Premium
class type sex;
N N N N Sum var totalclaim premium;
3.0
3.00 17.00 3359.15 table type;
0 17.00
table type premium;
Premium table type,premium;
Sum
table type,premium,sum;
run;
Type
I 312.65
Two-dimensional tables always
II
have row and column headings;
3046.50
Type I
  Sum Type II one-dimensional tables only
Premiu 312.6
  Sum have column headings.
m 5 Premiu 3046.5
m 0

SAS Techies 2009 11/02/21 9


 Your final task before writing your If you specify only class variables in
own PROC TABULATE step is to your TABLE statement,
specify the statistics needed. To  the default statistic is N
request a statistic, you use an (frequency)
operator, the asterisk (*), to attach
 the only statistics you can
the statistic to the variable.
request are N and PCTN (percent
of total frequency).

proc tabulate data=clinic.admit; If you specify any analysis variables


in your TABLE statement,
class sex actlevel;  the default statistic is SUM
var height weight;  you can request any statistic to
table height*mean weight*max,actlevel; be computed on the analysis
table sex*pctn actlevel*n; run; variables.

In a TABLE statement, you can


specify statistics in any
dimension, but they must all be
in the same dimension.

SAS Techies 2009 11/02/21 10


To specify a summary
 
Fee
Sum
proc tabulate; row, you specify ALL
data=clinic.admit;
Sex var fee; in the row expression
F 1418.35
class sex; of your TABLE
M table sex all,fee;
statement.
1268.60

All 2686.95 run;

Sex proc tabulate


F M
All data=clinic.admit;
N N N
class sex;
11 10 21 table sex all;
run;

SAS Techies 2009 11/02/21 11


proc tabulate data=clinic.admit;
class sex;
var height weight;
Lowest Highest Average table (height weight)*mean,sex
  Reading Reading Reading all;
label sex='Sex of Patient'
Sex height='Height' weight='Weight';
F Fasting keylabel min='Lowest Reading'
Glucose max='Highest Reading'
Level 152.00 568.00 253.45 mean='Average Reading';
M Fasting Run;
Glucose
Level 156.00 492.00 354.89

SAS Techies 2009 11/02/21 12


concatenation, using the blank
Operator to display variables
side by side or stacked To group elements and control how
expressions are evaluated, you can
use the parentheses operator.
table type*(sex all);

table height*mean weight*mean,sex all;

table sex,actlevel*age*max;

You can also produce hierarchical


tables by using the asterisk operator
to cross class variables with other
variables.

SAS Techies 2009 11/02/21 13


You can condense multiple pages into a single page. Condensed output
table type,fee,sum / condense;

proc format;
value $actfmt 'LOW'='(1) Low'
'MOD'='(2) Moderate'
'HIGH'='(3) High';

table type,fee*sex*pctsum<type>;

You can create formats to change headings


for class variable values.

You can specify how percentages are calculated.

SAS Techies 2009 11/02/21 14


Error How to rectify
VARIABLE appears in both CLASS and VAR lists.
You specified a variable as both
class and analysis.

Type of name (VARIABLE) unknown at line n.


You forgot to specify a variable as
either class or analysis.
Variable VARIABLE in list does not match type prescribed for this list.
You specified a character variable as
analysis.

SAS Techies 2009 11/02/21 15


 Descriptive statistics
Variable N Mean Std Dev Minimum Maximum such as mean, sum,
Age
Height
20
20
47
67
13
4
15
61
63
75 minimum, and maximum
can answer basic
Weight 20 175 36 102 240
Pulse 20 75 8 65 100
FastGluc 20 299 126 152 568
PostGluc 20 355 126 206 625 questions about numeric
proc means data=clinic.diabetes data.
N mean std min max;
run;
 If variables are not
Variable Minimum Maximum
specified, statistics on
all the variables are
Age 15 63
Height 61 75
Weight 102 240
Pulse
FastGluc
65
152
100
568
calculated..
PostGluc 206 625
var age height weight;
proc means data=clinic.diabetes
min max maxdec=0; run;

SAS Techies 2009 11/02/21 16


proc means data=flights.laguardia
median maxdec=0; var boarded
 CLASS Group
transferred deplaned; Processing You will
class Dest;
run
often want statistics
for grouped
Dest N Obs Variable Median observations, instead
CPH 6 Boarded
Transferred
137
12
of for observations
FRA 7
Deplaned
Boarded
149
176
as a whole.
Transferred 12
Deplaned 189
LON 20 Boarded 186
Transferred 11
Deplaned 200
PAR 13 Boarded 155
Transferred 15
Deplaned 182

SAS Techies 2009 11/02/21 17


 proc sort data=clinic.heart  Like the CLASS statement,
out=work.hartsort; by survive sex;
run; the BY statement specifies
 proc means data=work.hartsort variables to use for
maxdec=1; var arterial heart categorizing observations.
cardiac urinary; by survive sex;
run;
 Unlike CLASS processing,
BY processing requires
that your data already be
Survive=DIED Sex=2 sorted in the order of the
Variable N Mean Std Dev Minimum Maximum BY variables.
Arterial
Heart
6
6
94.2
103.7
27.3
16.7
72.0
81.0
145.0
130.0
 BY group results have a
Cardiac
Urinary
6
6
318.3
100.3
102.6
155.7
156.0
0.0
424.0
405.0
layout that is different
Survive=SURV from that of CLASS group
Sex=1
Variable N Mean Std Dev Minimum Maximum results.
Arterial 5 77.2 12.2 61.0 88.0
Heart 5 109.0 32.0 77.0 149.0
Cardiac 5 298.0 139.8 66.0 410.0
Urinary 5 100.8 60.2 44.0 200.0

SAS Techies 2009 11/02/21 18


Cumulati
ve Cumulati
Frequenc Frequenc ve  By default, PROC FREQ creates a one-way table
Variable y Percent y Percent with the frequency, percent, cumulative
Value Number of Frequency Sum of the Cumulative frequency, and cumulative percent of every
observations of the value frequency frequency of value of all variables in a data set.
with the divided by counts of the value
value. the total the value divided by
number of
observations
and all other
values listed
the total
number of
 Frequency distributions
. above it in
the table.
observation
work best with variables
Cumulative Cumulative that contain repeating
Rate Frequency Percent Frequency Percent
values.
9.50% 2 22.22 2 22.22

9.75% 1 11.11 3 33.33


proc freq
10.00
2 22.22 5 55.56
data=finance.loans; tables
%
Cumulative Cumulative rate months; run;
10.50
Months Frequency Percent Frequency Percent
4 44.44 9 100.00
%
12 1 11.11 1 11.11

24 1 11.11 2 22.22 Note: One table per variable


36 1 11.11 3 33.33 in one-way freq tables
48 1 11.11 4 44.44

60 2 22.22 6 66.67

360 3 33.33 9 100.00


SAS Techies 2009 11/02/21 19
SAS Data Set Clinic.Diabetes  ORDER=DATA|FORMATTED|FREQ|
ID Sex Age Height Weight Pulse FastGluc PostGluc INTERNAL where
2304 F 16 61 102 100 568 625
1128 M 43 71 218 76 156 208  DATA orders values by appearance in
4425 F 48 66 162 80 244 322 the data set
1387 F 57 64 142 70 177 206
 FORMATTED orders by formatted value
Cumulative Cumulative  FREQ orders values by descending
ht Frequency Percent Frequ Perce frequency count
ency nt
 INTERNAL orders by unformatted value
61 2 10.00 2 10.00 (default).
71 2 10.00 4 20.00

66 2 10.00 6 30.00
Cumulativ Cumulativ
eigh Frequenc Percen e e
Cumulative Cumulative t y t Frequ Perce
Frequ Perce ency nt
Height Frequency Percent ency nt
64 3 15.00 3 15.00
Medium 8 40.00 8 40.00
61 2 10.00 5 25.00
Short 7 35.00 15 75.00
65 2 10.00 7 35.00
Tall 5 25.00 20 100.00
66 2 10.00 9 45.00

SAS Techies 2009 11/02/21 20


Frequency Table of Weight by Height
Height
Percent
Row Pct
< 5'5"
5'5-
> 5'10"
 To create a two-way
table, join two
Col Pct Weight 10" Total
< 140 2 0 0 2
10.00
100.00
28.57
0.00
0.00
0.00
0.00
0.00
0.00
10.00
 
 
variables with
140- 5
25.00
5
25.00
0
0.00
10
50.00
asterisks (*) in the
TABLES statement of
180
50.00 50.00 0.00  
71.43 62.50 0.00  

> 180 0
0.00
3
15.00
5
25.00
8
40.00 a PROC FREQ step.
0.00 37.50 62.50  
0.00 37.50 100.00  

Total 7 8 5 20
35.00 40.00 25.00 100.00

proc format;
value wtfmt
low-139='< 140' 140-180='140-180' 181-high='> 180';
value htfmt low-64='< 5''5"' 65-70='5''5-10"' 71-high='> 5''10"'; run;
proc freq data=clinic.diabetes;
tables weight*height;
format weight wtfmt. height htfmt.;
run; SAS Techies 2009 11/02/21 21
Frequency Table 1 of Weight by Height
Controlling for Sex=F
Perce
nt Height
Row
Pct 5'5-
Col 1
< 5'5" > 5'10"
Pct 0
"
Weight Total
< 140 2 0 0 2 levels v
1
8.
0.
00
0.
00
1
8
tables sex*weight*height;
1
8
0.
00
0.
00 1
. ^ ^
1 0. . 8 rows + columns = two-way tables
0 00
0.  
0  
0 proc freq data=clinic.diabetes;
2
8.
tables sex*weight*height;
Frequency Table 2 5of Weight by Height
7
format weight weight. height height.; run;
Controlling for Sex=M
Perce 5 4 0 9
140-
nt 4 Height
36 0. 8
18
Row 5. .3 00 1
0 4
Pct 5'5-6 0. .
Col 5 441 00 8
< 5'5"5 .4 > 5'10". 2
Pct 5. 04
5 10 "
Weight Total 
6 0.  
< 140 7
0 00 0 0 0
1.
0. 0. 0. 0
4
0 00 00 .
3
0 . . 0
. 0. 0. 0
> 180 0
. 00 0 0
00 0
0. 0. 0. 0 
0 00 00 .  SAS Techies 2009 11/02/21 22
0 . . 0
Cumulative Cumulative
Freque Percen
Sex Weight Height Frequency Percent ncy t
F < 140 < 5'5" 2 10.00 2 10.00

F 140-180 < 5'5" 5 25.00 7 35.00

F 140-180 5'5-10" 4 20.00 11 55.00

M 140-180 5'5-10" 1 5.00 12 60.00

M > 180 5'5-10" 3 15.00 15 75.00

M > 180 > 5'10" 5 25.00 20 100.00

To generate list output for


proc freq data=clinic.diabetes; crosstabulations, add a slash
tables sex*weight*height / list; (/) and the LIST option to the
format weight wtfmt. height htfmt.; run; TABLES statement in your
PROC FREQ step.
TABLES variable-1*variable-2
<* ... variable-n> / LIST;

SAS Techies 2009 11/02/21 23


 NOFREQ suppresses
proc freq data=clinic.diabetes;
cell frequencies
tables sex*weight / nofreq norow nocol;
format weight weight.; run;
 NOPERCENT
suppresses cell
Percent Table of Sex by Weight
Weight
percentages
< 140
140-
18 > 180
 NOROW supresses
Sex 0 Total row percentages
F 10.00 45.00 0.00 55.00

M 0.00 5.00 40.00 45.00


 NOCOL suppresses
Total 2
1
10
50.
8
4
20
1 column percentages
0 00 0 0
. . 0
0 0 .
0 0 0
0

SAS Techies 2009 11/02/21 24

Das könnte Ihnen auch gefallen