SAS PROC REPORT PROC TABULATE Computing for Research I January 27, 2014.
-
Upload
bethany-merritt -
Category
Documents
-
view
243 -
download
3
Transcript of SAS PROC REPORT PROC TABULATE Computing for Research I January 27, 2014.
SASPROC 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><[style-
attribute-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 variablesANALYSIS – default for numeric variablesORDER – 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
Blood
PressureSubject Visit Systolic Diastolic
1020 Baseline 160 80 Day 1 160 801021 Baseline 145 100 Day 1 151 701022 Baseline 195 105 Day 1 145 851023 Baseline 135 75 Day 1 158 941024 Baseline 186 80 Day 1 186 801025 Baseline 146 82 Day 1 146 821026 Baseline 155 85 Day 1 165 851027 Baseline 134 80 Day 1 134 821028 Baseline 178 83 Day 1 160 861029 Baseline 180 75
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 VisitNmSystolic Blood
PressureDiastolic Blood
Pressure1020 Baseline 160 80
1020 Day 1 160 801021 Baseline 145 1001021 Day 1 151 701022 Baseline 195 1051022 Day 1 145 85
1023 Baseline 135 751023 Day 1 158 941024 Baseline 186 801024 Day 1 186 801025 Baseline 146 821025 Day 1 146 82
1026 Baseline 155 851026 Day 1 165 851027 Baseline 134 801027 Day 1 134 82
1028 Baseline 178 831028 Day 1 160 861029 Baseline 180 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
Average Blood PressureVisit Systolic Diastolic
Baseline 159 81
Day 1 163 83Day 2 169 87Day 3 170 89Day 4 170 91Day 5 174 91Day 6 173 89Day 7 173 90Day 8 174 90Day 9 170 90Day 10 170 88Day 11 166 91Day 12 170 91Day 13 168 90Day 14 161 89Day 15 159 86
169 88
Proc Means Comparison: Example 2
VisitNm N Obs Variable Label MeanBaseline 47 SBP
DBPSystolic Blood PressureDiastolic Blood Pressure
158.936170280.5744681
Day 1 46 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
162.782608783.3043478
Day 10 36 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
169.888888988.3888889
Day 11 33 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
166.303030391.0000000
Day 12 26 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
170.269230891.0384615
Day 13 26 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
167.846153889.5769231
Day 14 24 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
161.416666789.0833333
Day 15 19 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
158.736842185.6315789
Day 2 47 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
168.574468187.4680851
…
ods rtf;title 'Average Blood Pressure by Visit';proc means data=vitals mean;
class visitnm;var SBP DBP;
run;ods rtf close;
Proc Report Resources
• SAS Documentation
• Learning Proc Reporthttp://www2.sas.com/proceedings/forum2008/170-2008.pdf
• Proc Report Advanced Tutorialhttp://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 Statementidentifies the class variables (character or numeric)determines the categories that Proc Tabulate uses to calculate statisticsMissing Option - if not included, observations with any missing class variable values are excluded from the table
Var StatementIdentifies 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
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
VisitsBaseline Day 1
N % N %All 10 52.63 9 47.37
SubjectID
1 5.26 1 5.2610201021 1 5.26 1 5.26
1022 1 5.26 1 5.26
1023 1 5.26 1 5.26
1024 1 5.26 1 5.26
1025 1 5.26 1 5.26
1026 1 5.26 1 5.26
1027 1 5.26 1 5.26
1028 1 5.26 1 5.26
1029 1 5.26 MISSING 0.00
Example 1: Proc Freq Comparison
Table of SubjectID by VisitNm
SubjectID(SubjectID) VisitNm(VisitNm)FrequencyPercent Baseline Day 1 Total
1020 15.26
15.26
210.53
1021 15.26
15.26
210.53
1022 15.26
15.26
210.53
1023 15.26
15.26
210.53
1024 15.26
15.26
210.53
1025 15.26
15.26
210.53
1026 15.26
15.26
210.53
1027 15.26
15.26
210.53
1028 15.26
15.26
210.53
1029 15.26
00.00
15.26
Total 1052.63
947.37
19100.00
proc freq data=vitals;
where visitid in (1,2) and 1020 le subjectid le 1029;
table subjectid*visitnm /norow nocol;
run;
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
Systolic Blood Pressure Diastolic Blood Pressure
N Mean SD N Mean SDAll 19 158.9 18.6 19 83.6 8.3
SubjectID
2 160.0 0.0 2 80.0 0.01020
1021 2 148.0 4.2 2 85.0 21.2
1022 2 170.0 35.4 2 95.0 14.1
1023 2 146.5 16.3 2 84.5 13.4
1024 2 186.0 0.0 2 80.0 0.0
1025 2 146.0 0.0 2 82.0 0.0
1026 2 160.0 7.1 2 85.0 0.0
1027 2 134.0 0.0 2 81.0 1.4
1028 2 169.0 12.7 2 84.5 2.1
1029 1 180.0 . 1 75.0 .
Average Blood Pressure Across Baseline and Day 1
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;
SubjectID
N Ob
s Variable Label Mean Std Dev1020 2 SBP
DBPSystolic Blood PressureDiastolic Blood Pressure
160.000000080.0000000
00
1021 2 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
148.000000085.0000000
4.242640721.2132034
1022 2 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
170.000000095.0000000
35.355339114.1421356
1023 2 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
146.500000084.5000000
16.263456013.4350288
1024 2 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
186.000000080.0000000
00
1025 2 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
146.000000082.0000000
00
1026 2 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
160.000000085.0000000
7.07106780
1027 2 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
134.000000081.0000000
01.4142136
1028 2 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
169.000000084.5000000
12.72792212.1213203
1029 1 SBPDBP
Systolic Blood PressureDiastolic Blood Pressure
180.000000075.0000000
.
.
Proc Tabulate Resources
SAS Documentation Proc Tabulate Introductionhttp://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?