SAS PROC REPORT PROC TABULATE

advertisement
SAS
PROC REPORT
PROC TABULATE
Computing for Research I
January 27, 2014
PROC REPORT
Proc Report Intro


Similar to Proc Print, with more control over
output appearance and format
Produces detail reports (data listings) and
summary reports
Proc Report Syntax Basics
PROC REPORT data=dataset <options>;
COLUMN var1 var2 var3;
DEFINE var1 / <options>;
DEFINE var2 / <options>;
RUN;
Proc Report Statement



DATA= input data set
NOWD/NOWINDOWS Option - non-interactive mode
Additional Options - control layout of the report
–
–
–
–
–
COLWIDTH=
MISSING
SPLIT=‘character’
SPANROWS (for ODS only)
STYLE<(location(s))>=<style-element-name><[styleattribute-specification(s)]> (for ODS only)
Other Statements
Column Statement - describes the arrangement of columns and
column headers that span >1 column
Define Statement
– Variable Appearance (format, label, justify)
– Variable Usage
DISPLAY – default for character variables
ANALYSIS – default for numeric variables
ORDER – determines row order
ORDER=FORMATTED | INTERNAL | DATA | FREQ
GROUP – consolidates unique values of GROUP variables
into one row
Rbreak Statement - produces a default summary at the beginning
or end of a report or at the beginning or end of each BY group.
Vital Signs Dataset




SubjectID (47 subjects)
VisitID (1-16), Visit Nm (Baseline, Day 1 –
Day 15)
SBP, DBP, Heart Rate, Central Venous
Pressure
1 record per subject per visit
Proc Report Code: Example 1
title 'Baseline and Day 1 Blood Pressure' ;
proc report data=vitals nowd split='*';
where visitid in (1,2) and 1020 le subjectid le 1029;
columns subjectid visitnm ('Blood*Pressure' SBP DBP);
define subjectid / 'Subject' order;
define visitnm / 'Visit' ;
define SBP / 'Systolic' format=8. center;
define DBP / 'Diastolic' format=8. center;
run;
Proc Report Output: Example 1
Baseline and Day 1 Blood Pressure
Subject
Visit
1020 Baseline
Day 1
1021 Baseline
Day 1
1022 Baseline
Day 1
1023 Baseline
Day 1
1024 Baseline
Day 1
1025 Baseline
Day 1
1026 Baseline
Day 1
1027 Baseline
Day 1
1028 Baseline
Blood
Pressure
Systolic Diastolic
160
80
160
80
145
100
151
70
195
105
145
85
135
75
158
94
186
80
186
80
146
82
146
82
155
85
165
85
134
80
134
82
178
83
Proc Print Comparison: Example 1
proc sort data=vitals;
by subjectid;
run;
proc print data=vitals label
noobs;
where visitid in (1,2) and
1020 le subjectid le 1029;
var subjectid visitnm SBP DBP;
run;
SubjectID
1020
1020
1021
1021
1022
1022
1023
1023
1024
1024
1025
1025
1026
1026
1027
1027
1028
1028
1029
VisitNm
Baseline
Day 1
Baseline
Day 1
Baseline
Day 1
Baseline
Day 1
Baseline
Day 1
Baseline
Day 1
Baseline
Day 1
Baseline
Day 1
Baseline
Day 1
Baseline
Systolic Blood
Pressure
160
160
145
151
195
145
135
158
186
186
146
146
155
165
134
134
178
160
180
Diastolic Blood
Pressure
80
80
100
70
105
85
75
94
80
80
82
82
85
85
80
82
83
86
75
Proc Report Code: Example 2
ods rtf;
title 'Average Blood Pressure by Visit';
proc report data=vitals nowd split='*'
style(header)=[fontsize=14pt textalign=center
foreground=white background=black];
columns visitnm ('Average*Blood Pressure' SBP DBP);
define visitnm / 'Visit' group order=data;
define SBP / 'Systolic' format=8. center mean;
define DBP / 'Diastolic' format=8. center mean;
rbreak after /summarize;
run;
ods rtf close;
Proc Report Output: Example 2
Average Blood Pressure by Visit
Visit
Average Blood Pressure
Systolic
Diastolic
Baseline
159
81
Day 1
Day 2
Day 3
Day 4
Day 5
Day 6
Day 7
Day 8
Day 9
Day 10
Day 11
Day 12
Day 13
Day 14
Day 15
163
169
170
170
174
173
173
174
170
170
166
170
168
161
159
169
83
87
89
91
91
89
90
90
90
88
91
91
90
89
86
88
Proc Means Comparison: Example 2
ods rtf;
title 'Average Blood
Pressure by Visit';
proc means data=vitals
mean;
class visitnm;
var SBP DBP;
run;
ods rtf close;
VisitNm N Obs Variable Label
Baseline
Day 1
Day 10
Day 11
Day 12
Day 13
Day 14
Day 15
Day 2
…
47 SBP
DBP
46 SBP
DBP
36 SBP
DBP
33 SBP
DBP
26 SBP
DBP
26 SBP
DBP
24 SBP
DBP
19 SBP
DBP
47 SBP
DBP
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Mean
158.9361702
80.5744681
162.7826087
83.3043478
169.8888889
88.3888889
166.3030303
91.0000000
170.2692308
91.0384615
167.8461538
89.5769231
161.4166667
89.0833333
158.7368421
85.6315789
168.5744681
87.4680851
Proc Report Resources
• SAS Documentation
• Learning Proc Report
http://www2.sas.com/proceedings/forum2008/170-2008.pdf
• Proc Report Advanced Tutorial
http://www2.sas.com/proceedings/sugi28/015-28.pdf
PROC TABULATE
Proc Tabulate Intro


Similar to Proc Means and Proc Freq, in
tabular format
Creates summary reports with descriptive
statistics
Proc Tabulate Syntax Basics
PROC TABULATE data=dataset;
CLASS classification variables;
VAR analysis variables;
TABLE page dimension,
row dimension,
column dimension / <options>;
RUN;
Class and Var Statements
Class Statement
 identifies the class variables (character or numeric)
 determines the categories that Proc Tabulate uses to
calculate statistics
 Missing Option - if not included, observations with
any missing class variable values are excluded from
the table
Var Statement
 Identifies numeric variables to use as analysis
variables.
Table Statement





Required for procedure
Describes the table to create
Format: page variables, row variables, column
variables
Can include variable names, keyword statistics, and
operators
Options
–
–
–
PRINTMISS
MISSTEXT=
BOX=
Table Statement Operators




Comma – starts a new dimension
Blank – concatenates elements
Asterisk – creates categories from the
combination of values of the class variables
and calculates appropriate statistics if class
and analysis variables are crossed
Parentheses – groups elements, associates
operator with each element in the group
Table Statement Statistic Keywords
N
NMISS
PCTN
COLPCTN
ROWPCTN
MEAN
STD
MIN
MAX
MEDIAN
Q1
Q3
many more…
Other Statements



KEYLABEL – labels a statistic keyword
KEYWORD – specifies a style element for
keyword headings
CLASSLEV – specifies a style element for
class variable level value headings
Proc Tabulate Code: Example 1
proc tabulate data=vitals;
where visitid in (1,2) and
1020 le subjectid le 1029;
class subjectid visitnm;
table all subjectid,
(visitnm='Visits')*(n pctn='%') /
box=[label='Subjects x Visits']
misstext='MISSING' printmiss;
run;
Proc Tabulate Output: Example 1
Subjects x
Visits
All
SubjectID
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
Visits
Baseline
N
%
Day 1
N
%
10
52.63
9
47.37
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
MISSING
0.00
Example 1: Proc Freq Comparison
proc freq data=vitals;
where visitid in (1,2) and
1020 le subjectid le 1029;
table subjectid*visitnm
/norow nocol;
run;
Table of SubjectID by VisitNm
SubjectID(SubjectID)
VisitNm(VisitNm)
Frequency
Percent
Baseline
Day 1
Total
1
1
2
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
Total
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
10
52.63
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
1
5.26
0
0.00
9
47.37
10.53
2
10.53
2
10.53
2
10.53
2
10.53
2
10.53
2
10.53
2
10.53
2
10.53
1
5.26
19
100.00
Proc Tabulate Code: Example 2
title 'Average Blood Pressure Across Baseline and
Day 1';
proc tabulate data=vitals;
where visitid in (1,2)
and 1020 le subjectid le 1029;
class subjectid ;
var SBP DBP;
table all subjectid,
(SBP DBP)*(n mean*f=8.1 std*f=8.1);
keylabel std='SD';
run;
Proc Tabulate Output: Example 2
Average Blood Pressure Across Baseline and Day 1
Systolic Blood Pressure Diastolic Blood Pressure
N
Mean
SD
N
Mean
SD
All
SubjectID
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
19
158.9
18.6
19
83.6
8.3
2
160.0
0.0
2
80.0
0.0
2
148.0
4.2
2
85.0
21.2
2
170.0
35.4
2
95.0
14.1
2
146.5
16.3
2
84.5
13.4
2
186.0
0.0
2
80.0
0.0
2
146.0
0.0
2
82.0
0.0
2
160.0
7.1
2
85.0
0.0
2
134.0
0.0
2
81.0
1.4
2
169.0
12.7
2
84.5
2.1
1
180.0
.
1
75.0
.
Example 2: Proc Means Comparison
proc means data=vitals
mean std;
where visitid in
(1,2) and 1020
le subjectid
le 1029;
class subjectid;
var SBP DBP;
run;
N
SubjectID Obs Variable Label
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
2 SBP
DBP
2 SBP
DBP
2 SBP
DBP
2 SBP
DBP
2 SBP
DBP
2 SBP
DBP
2 SBP
DBP
2 SBP
DBP
2 SBP
DBP
1 SBP
DBP
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Systolic Blood Pressure
Diastolic Blood Pressure
Mean
Std Dev
160.0000000
80.0000000
148.0000000
85.0000000
170.0000000
95.0000000
146.5000000
84.5000000
186.0000000
80.0000000
146.0000000
82.0000000
160.0000000
85.0000000
134.0000000
81.0000000
169.0000000
84.5000000
180.0000000
75.0000000
0
0
4.2426407
21.2132034
35.3553391
14.1421356
16.2634560
13.4350288
0
0
0
0
7.0710678
0
0
1.4142136
12.7279221
2.1213203
.
.
Proc Tabulate Resources


SAS Documentation
Proc Tabulate Introduction
http://www.sascommunity.org/mwiki/images/4/49/Proc_Tabulate_how_to_-_version_2.0.pdf

Using Style Elements in the REPORT and
TABULATE Procedures
http://support.sas.com/resources/papers/stylesinprocs.pdf
Reporting Data

Plan the layout
–
–
–
–

Summary statistics, analysis output or data
listings?
Content of columns/rows?
Order of columns/rows?
Font
Use a report writing tool
QUESTIONS?
Download