Contents
Chapter 1 􀀀 Introduction to the SQL Procedure 1
What Is SQL? 1
What Is the SQL Procedure? 1
Terminology 2
Comparing PROC SQL with the SAS DATA Step 3
Notes about the Example Tables 4
Chapter 2 􀀀 Retrieving Data from a Single Table 11
Overview of the SELECT Statement 12
Selecting Columns in a Table 14
Creating New Columns 18
Sorting Data 25
Retrieving Rows That Satisfy a Condition 30
Summarizing Data 39
Grouping Data 45
Filtering Grouped Data 50
Validating a Query 52
Chapter 3 􀀀 Retrieving Data from Multiple Tables 55
Introduction 56
Selecting Data from More Than One Table by Using Joins 56
Using Subqueries to Select Data 74
When to Use Joins and Subqueries 80
Combining Queries with Set Operators 81
Chapter 4 􀀀 Creating and Updating Tables and Views 89
Introduction 90
Creating Tables 90
Inserting Rows into Tables 93
Updating Data Values in a Table 96
Deleting Rows 98
Altering Columns 99
Creating an Index 102
Deleting a Table 103
Using SQL Procedure Tables in SAS Software 103
Creating and Using Integrity Constraints in a Table 103
Creating and Using PROC SQL Views 105
Chapter 5 􀀀 Programming with the SQL Procedure 111
Introduction 111
Using PROC SQL Options to Create and Debug Queries 112
Improving Query Performance 115
Accessing SAS System Information Using DICTIONARY Tables 117
Using PROC SQL with the SAS Macro Facility 120
Formatting PROC SQL Output Using the REPORT Procedure 127
Accessing a DBMS with SAS/ACCESS Software 128
Using the Output Delivery System (ODS) with PROC SQL 132
Chapter 6 􀀀 Practical Problem-Solving with PROC SQL 133
Overview 134
Computing a Weighted Average 134
Comparing Tables 136
Overlaying Missing Data Values 138
Computing Percentages within Subtotals 140
Counting Duplicate Rows in a Table 141
Expanding Hierarchical Data in a Table 143
Summarizing Data in Multiple Columns 144
Creating a Summary Report 146
Creating a Customized Sort Order 148
Conditionally Updating a Table 150
Updating a Table with Values from Another Table 153
Creating and Using Macro Variables 154
Using PROC SQL Tables in Other SAS Procedures 157
Appendix 1 􀀀 Recommended Reading 161
Recommended Reading 161
Glossary 163
Index 167