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><[style-attribute-specification(s)]> (for ODS only) SPANROWS - specifies that a single cell will occupy the column in all the rows for which the value is the same. Only applies to ODS MARKUP, PDF, RTF, and PRINTER destinations. STYLE<(location(s))>=<style-element-name><[style-attribute-specification(s)]>specifies one or more style elements (for the Output Delivery System) to use for different parts of the report. COLWIDTH=column-width - specifies the default number of characters for columns containing computed variables or numeric data set variables. MISSING - considers missing values as valid values for group, order, or across variables. SPLIT='character‘ - specifies the split character.
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 Blood Pressure Subject Visit Systolic Diastolic 1020 Baseline 160 80 Day 1 1021 145 100 151 70 1022 195 105 85 1023 135 75 158 94 1024 186 1025 146 82 1026 155 165 1027 134 1028 178 83 86 1029 180
Proc Print Comparison: Example 1 SubjectID VisitNm Systolic Blood Pressure Diastolic Blood Pressure 1020 Baseline 160 80 Day 1 1021 145 100 151 70 1022 195 105 85 1023 135 75 158 94 1024 186 1025 146 82 1026 155 165 1027 134 1028 178 83 86 1029 180 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;
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 Pressure Visit Systolic Diastolic Baseline 159 81 Day 1 163 83 Day 2 169 87 Day 3 170 89 Day 4 91 Day 5 174 Day 6 173 Day 7 90 Day 8 Day 9 Day 10 88 Day 11 166 Day 12 Day 13 168 Day 14 161 Day 15 86
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 Mean Baseline 47 SBP DBP Systolic Blood Pressure Diastolic Blood Pressure 158.9361702 80.5744681 Day 1 46 162.7826087 83.3043478 Day 10 36 169.8888889 88.3888889 Day 11 33 166.3030303 91.0000000 Day 12 26 170.2692308 91.0384615 Day 13 167.8461538 89.5769231 Day 14 24 161.4166667 89.0833333 Day 15 19 158.7368421 85.6315789 Day 2 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; Depending on the variables you are looking at, the ‘class’ and ‘var’ statements will be required (at least one is required). Var statement used to analyze numeric variables.
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 Visits Baseline Day 1 N % All 10 52.63 9 47.37 SubjectID 1 5.26 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 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 1020 1 5.26 2 10.53 1021 1022 1023 1024 1025 1026 1027 1028 1029 0 0.00 10 52.63 9 47.37 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 All 19 158.9 18.6 83.6 8.3 SubjectID 2 160.0 0.0 80.0 1020 1021 148.0 4.2 85.0 21.2 1022 170.0 35.4 95.0 14.1 1023 146.5 16.3 84.5 13.4 1024 186.0 1025 146.0 82.0 1026 7.1 1027 134.0 81.0 1.4 1028 169.0 12.7 2.1 1029 1 180.0 . 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; SubjectID N Obs Variable Label Mean Std Dev 1020 2 SBP DBP Systolic Blood Pressure Diastolic Blood Pressure 160.0000000 80.0000000 0 0 1021 148.0000000 85.0000000 4.2426407 21.2132034 1022 170.0000000 95.0000000 35.3553391 14.1421356 1023 146.5000000 84.5000000 16.2634560 13.4350288 1024 186.0000000 80.0000000 1025 146.0000000 82.0000000 1026 160.0000000 85.0000000 7.0710678 0 1027 134.0000000 81.0000000 0 1.4142136 1028 169.0000000 84.5000000 12.7279221 2.1213203 1029 1 180.0000000 75.0000000 . .
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 Use a report writing tool Summary statistics, analysis output or data listings? Content of columns/rows? Order of columns/rows? Font Use a report writing tool
QUESTIONS?