【分享】Carpenter’s Complete Guide to the SAS ®REPORT Procedure
Copyright © 2007, SAS Institute Inc., Cary, NC, USA
ISBN 978-1-59994-195-0
Contents
Preface xi
Acknowledgments xiii
About the Author xv
How to Use This Book and the Accompanying CD xvii
Part 1 Getting Started
Chapter 1 Creating a Simple Report 3
1.1 Basic Syntax 4
1.2 Routing Reports to ODS Destinations 6
1.3 Other Reporting Tools: A Brief Comparison of Capabilities 7
1.3.1 PROC REPORT vs. PROC PRINT 8
1.3.2 PROC REPORT vs. PROC TABULATE 8
1.3.3 PROC REPORT vs. DATA _NULL_ 8
1.4 The PROC REPORT Process: An Overview 9
1.4.1 PROC REPORT Terminology 9
1.4.2 Processing Phases 11
1.5 Chapter Exercises 12
Chapter 2 PROC REPORT: An Introduction 13
2.1 Introduction to the COLUMN Statement 16
2.2 Defining Types of Columns 17
2.2.1 Default Define Types DISPLAY and ANALYSIS 18
2.2.2 Using Define Usage ORDER 19
2.2.3 Using Define Type GROUP 22
2.2.4 Using Define Type ACROSS (and GROUP) 24
2.3 Doing More on the COLUMN Statement 25
2.3.1 Using the Comma to Form Nested Associations 26
2.3.2 Attaching Statistics with a Comma 26
2.3.3 Using Parentheses to Form Groups 28
2.3.4 Nesting Statistics under an ACROSS Variable 29
2.4 Other DEFINE Statement Options 31
2.4.1 Specification of an Analysis Statistic 31
2.4.2 Formatting the Values 33
2.4.3 Controlling the Order of the Displayed Values 34
2.4.4 Using the N Statistic without an ANALYSIS Variable 36
2.4.5 Associating Statistics with DEFINE Statements 37 iv Contents
2.5 Adding Text 39
2.5.1 Using the COLUMN Statement to Add Text 41
2.5.2 Using the DEFINE Statement to Add Text 43
2.5.3 Using the SPLIT= Option with Text 44
2.6 Compute Blocks 45
2.6.1 Inserting a Blank Line 46
2.6.2 Adding Lines of Text 47
2.6.3 Writing Formatted Values 49
2.6.4 Using SAS Language Elements 51
2.7 Sequencing of Step Events 52
2.8 Chapter Exercises 54
Chapter 3 Creating Breaks 57
3.1 Generating Breaks Using BREAK and RBREAK 57
3.2 BREAK Statement 59
3.2.1 Skipping a Line between Groups 59
3.2.2 Summarizing across a Group 61
3.2.3 Suppressing the Summarization Label 65
3.2.4 Generating a Page for Each Group Level 67
3.2.5 Combining Summaries with Detail Reports 68
3.3 RBREAK Statement 69
3.3.1 Using RBREAK in a Detail Report 69
3.3.2 Using RBREAK with BREAK in a Detail Report 70
3.3.3 Using RBREAK and BREAK in a Summary Report 71
3.4 Chapter Exercises 73
Chapter 4 Only in the LISTING Destination 75
4.1 Using the HEADLINE and HEADSKIP Options 76
4.2 Blank Lines, Overlines, and Underlines 78
4.3 Repeat Characters 79
4.3.1 Adding Repeated Characters to Spanning Headers 80
4.3.2 Repeat Characters with the SPLIT= Option 82
4.4 PROC REPORT Statement Options 83
4.4.1 Creating Boxes on the Report 83
4.4.2 Controlling the Centering of the Report 85
4.4.3 Adjusting the Width of Numeric and Computed Columns 85
4.4.4 Creating Multiple Panels on a Page 86
4.4.5 Using the PSPACE= Option 87
4.4.6 Controlling the Size of the Page 88
4.4.7 Using the FORMCHAR Option 89
4.4.8 Wrapping Data Lines 91 Contents v
4.5 Other DEFINE Statement Options 92
4.5.1 Specifying the Column Width 93
4.5.2 Using the FLOW Option to Wrap Text 93
4.5.3 Adding Spaces between Columns 94
4.6 Chapter Exercises 96
Chapter 5 Creating and Modifying Columns Using the
Compute Block 97
5.1 Coordinating with the COLUMN and DEFINE Statements 98
5.2 Calculations Based on Statistics 99
5.3 Calculating Percentages within Groups 101
5.4 Using _PAGE_ with BEFORE and AFTER 103
5.5 Using the OUT= Option to View Report Break Information 104
5.6 Chapter Exercises 106
Part 2 Taking PROC REPORT Beyond the
Basics
Chapter 6 Refining Our Understanding of the
PROC REPORT Step 109
6.1 Additional DEFINE Statement Options 110
6.1.1 Changing Display Order with DESCENDING 110
6.1.2 Specification of Column Justification 111
6.1.3 Allowing the Use of Missing Classification Items 113
6.1.4 Controlling the Use of Analysis Items with All Missing or
Zero Values 115
6.1.5 Using NOPRINT 118
6.1.6 Identification Columns 119
6.1.7 Creating Vertical Page Breaks 120
6.2 Using Variable Aliases 121
6.3 Nesting Variables 122
6.4 Taking Full Advantage of Formats 123
6.4.1 User-Defined Formats 123
6.4.2 Preloading Formats 126
6.4.3 Order Based on Format Definition 130
6.5 Other PROC Statement Options 131
6.5.1 Removing Headers 131
6.5.2 Using NAMED Output 132
6.5.3 Debugging with the LIST Option 134
6.5.4 Including MISSING Classification Levels 134 vi Contents
6.6 BY-Group Processing 136
6.6.1 Using the BY Statement 137
6.6.2 Creating Breaks with BY Groups 138
6.6.3 Using the #BYVAL and #BYVAR Options 139
6.6.4 BY Groups and the Output Delivery System 141
6.7 Calculations Using the FREQ Statement 144
6.8 A Further Comment on Paging Issues 145
6.9 Chapter Exercises 146
Chapter 7 Extending Compute Blocks 147
7.1 Understanding the Events of the Compute Block Process 149
7.1.1 Setup Phase: Generating the Computed Summary
Information 150
7.1.2 Report Row Phase: Generating the Report 150
7.1.3 Process Example 151
7.2 Referencing Columns and Report Items in a Compute Block 154
7.2.1 Using Direct Variable Name References 156
7.2.2 Using Compound Variable Names 159
7.2.3 Using an Alias as a Column Reference 160
7.2.4 Using Absolute Column References: Referring to a Column
by Its Number 161
7.2.5 Using the Automatic Temporary Variable _BREAK_ 164
7.3 Using BEFORE and AFTER 166
7.4 Changing the Grouping Variable Values on Summary Lines 169
7.4.1 Specifying Text in a Compute Block 170
7.4.2 Using a Formatted Value 171
7.4.3 Creating a Dummy Column 173
7.5 Introducing the CALL DEFINE Routine 174
7.6 COMPUTE Statement Options and Switches 179
7.6.1 Justification of LINE Statement Text 179
7.6.2 Creating Character Variables with the CHARACTER and
LENGTH= Options 180
7.7 Using Logic and SAS Language Elements 182
7.7.1 Using the SUM Statement with Temporary Variables 183
7.7.2 Repeating GROUP and ORDER Variables on Each Row 185
7.7.3 Counting Items across Page Breaks in the LISTING
Destination 187
7.8 Doing More with the LINE Statement 191
7.8.1 Creating Group Summaries 192
7.8.2 Adding Repeated Characters 194
7.8.3 Understanding LINE Statement Execution 197 Contents vii
7.9 Examples of Common Tasks 199
7.9.1 Writing a Grand Total on Every Page 200
7.9.2 Combining Values into One Field or Column 202
7.9.3 Combining Values with Nested ACROSS Variables 204
7.9.4 Calculating a Weighted Mean 206
7.10 Chapter Exercises 209
Chapter 8 Using PROC REPORT with ODS 211
8.1 Introduction to the STYLE= Option 213
8.2 Using STYLE= to Change Attributes 216
8.2.1 Changing Text and Cell Attributes 216
8.2.2 Adding a Logo to Your Report 219
8.2.3 Controlling Report Size 223
8.2.4 Adding Horizontal and Vertical Spaces to Separate
Data 223
8.3 Using CALL DEFINE to Change Style Attributes 227
8.3.1 Using CALL DEFINE in a Simple Report 228
8.3.2 Creating Shaded Rows 229
8.3.3 Conditional Assignment of Attributes 231