Preface |
|
xiii | |
The Author |
|
xix | |
Acknowledgments |
|
xxi | |
|
|
1 | (34) |
|
1.1 SAS Program and Language |
|
|
1 | (1) |
|
1.2 Reading Data into SAS |
|
|
2 | (7) |
|
1.2.1 The SAS Data Set and SAS Library |
|
|
2 | (1) |
|
1.2.2 Reading a SAS Data Set |
|
|
3 | (3) |
|
1.2.3 Reading a Raw Data File with Fixed Fields |
|
|
6 | (2) |
|
1.2.4 Reading Data Entered Directly into the Program |
|
|
8 | (1) |
|
1.3 Creating and Modifying Variables |
|
|
9 | (4) |
|
1.3.1 The Assignment Statement and SAS Expression |
|
|
9 | (3) |
|
1.3.2 Creating Variables Conditionally |
|
|
12 | (1) |
|
|
13 | (11) |
|
1.4.1 Common Statements in SAS Procedures: TITLE, BY, and WHERE Statements |
|
|
13 | (1) |
|
1.4.2 The CONTENTS Procedure |
|
|
14 | (2) |
|
|
16 | (1) |
|
1.4.4 The PRINT Procedure |
|
|
16 | (2) |
|
1.4.5 The MEANS Procedure |
|
|
18 | (2) |
|
|
20 | (4) |
|
1.5 Subsetting Data by Selecting Variables |
|
|
24 | (4) |
|
1.5.1 Selecting Variables with the KEEP= Data Set Option or KEEP Statement |
|
|
25 | (2) |
|
1.5.2 Selecting Variables with the DROP= Data Set Option or DROP Statement |
|
|
27 | (1) |
|
1.5.3 Where to Specify the DROP= and KEEP= Data Set Options and DROP/KEEP Statements |
|
|
27 | (1) |
|
1.6 Changing the Appearance of Data |
|
|
28 | (7) |
|
|
29 | (2) |
|
1.6.2 Formatting Variable Values Using SAS FORMATS |
|
|
31 | (2) |
|
|
33 | (2) |
|
2 Creating Variables Conditionally |
|
|
35 | (20) |
|
2.1 The IF-THEN/ELSE Statement |
|
|
35 | (10) |
|
2.1.1 Steps for Creating a Variable |
|
|
35 | (2) |
|
2.1.2 Handling Missing Values When Creating Variables |
|
|
37 | (2) |
|
2.1.3 TRUE and FALSE: Logical Expressions |
|
|
39 | (2) |
|
2.1.4 The LENGTH Attribute |
|
|
41 | (2) |
|
|
43 | (2) |
|
2.2 Executing One of Several Statements |
|
|
45 | (7) |
|
2.2.1 Multiple IF-THEN/ELSE Statements |
|
|
45 | (3) |
|
2.2.2 Executing Statements Using the SELECT Group |
|
|
48 | (4) |
|
2.3 Modifying the IF-THEN/ELSE Statement with the Assignment Statement |
|
|
52 | (3) |
|
|
54 | (1) |
|
3 Understanding How the DATA Step Works |
|
|
55 | (24) |
|
3.1 DATA Step Processing Overview |
|
|
55 | (7) |
|
3.1.1 DATA Step Compilation Phase |
|
|
57 | (1) |
|
3.1.2 DATA Step Execution Phase |
|
|
58 | (3) |
|
3.1.3 The Importance of the OUTPUT Statement |
|
|
61 | (1) |
|
3.1.4 The Difference between Reading a Raw Data Set and a SAS Data Set |
|
|
61 | (1) |
|
3.2 Retaining the Value of Newly Created Variables |
|
|
62 | (4) |
|
3.2.1 The RETAIN Statement |
|
|
62 | (2) |
|
|
64 | (2) |
|
3.3 Conditional Processing in the DATA Step |
|
|
66 | (4) |
|
3.3.1 The Subsetting IF Statement |
|
|
66 | (2) |
|
3.3.2 Detecting the End of a Data Set by Using the END= Option |
|
|
68 | (1) |
|
3.3.3 Restructuring Data Sets from Wide Format to Long Format |
|
|
68 | (2) |
|
|
70 | (9) |
|
3.4.1 Using the PUT Statement to Observe the Contents of the PDV |
|
|
70 | (4) |
|
3.4.2 Using the DATA Step Debugger |
|
|
74 | (2) |
|
|
76 | (3) |
|
4 BY-Group Processing in the DATA Step |
|
|
79 | (16) |
|
4.1 Introduction to BY-Group Processing |
|
|
79 | (6) |
|
4.1.1 The FIRST.VARIABLE and the LAST.VARIABLE |
|
|
79 | (2) |
|
4.1.2 The Execution Phase of BY-Group Processing |
|
|
81 | (4) |
|
4.2 Applications Utilizing BY-Group Processing |
|
|
85 | (10) |
|
4.2.1 Calculating Mean Score within Each BY Group |
|
|
87 | (1) |
|
4.2.2 Creating Data Sets with Duplicate or Non-Duplicate Observations |
|
|
88 | (1) |
|
4.2.3 Obtaining the Most Recent Non-Missing Data within Each BY Group |
|
|
89 | (2) |
|
4.2.4 Restructuring Data Sets from Long Format to Wide Format |
|
|
91 | (1) |
|
|
92 | (3) |
|
5 Writing Loops in the DATA Step |
|
|
95 | (26) |
|
5.1 Implicit and Explicit Loops |
|
|
95 | (8) |
|
|
95 | (1) |
|
|
96 | (6) |
|
|
102 | (1) |
|
5.1.4 Combining Implicit and Explicit Loops |
|
|
103 | (1) |
|
5.2 Utilizing Loops to Create Samples |
|
|
103 | (7) |
|
|
104 | (1) |
|
5.2.2 Creating a Systematic Sample |
|
|
105 | (1) |
|
5.2.3 Creating a Random Sample with Replacement |
|
|
106 | (2) |
|
5.2.4 Creating a Random Sample without Replacement |
|
|
108 | (2) |
|
5.3 Using Looping to Read a List of External Files |
|
|
110 | (11) |
|
5.3.1 Using an Iterative DO Loop to Read an External File |
|
|
110 | (1) |
|
5.3.2 Using an Iterative DO-Loop to Read Multiple External Files |
|
|
111 | (6) |
|
|
117 | (4) |
|
|
121 | (18) |
|
6.1 Introduction to Array Processing |
|
|
121 | (5) |
|
6.1.1 Situations for Utilizing Array Processing |
|
|
121 | (2) |
|
6.1.2 Defining and Referencing One-Dimensional Arrays |
|
|
123 | (2) |
|
6.1.3 Compilation and Execution Phases for Array Processing |
|
|
125 | (1) |
|
6.2 Functions and Operators Related to Array Processing |
|
|
126 | (4) |
|
6.2.1 The DIM, HBOUND, and LBOUND Functions |
|
|
126 | (3) |
|
6.2.2 Using the IN and OF Operator with an Array |
|
|
129 | (1) |
|
6.3 Some Array Applications |
|
|
130 | (3) |
|
6.3.1 Creating a Group of Variables by Using Arrays |
|
|
130 | (1) |
|
6.3.2 Calculating Products of Multiple Variables |
|
|
131 | (1) |
|
6.3.3 Restructuring Data Sets Using One-Dimensional Arrays |
|
|
132 | (1) |
|
6.4 Applications That Use Multi-Dimensional Arrays |
|
|
133 | (6) |
|
6.4.1 Calculating Average SBP for Pre- and Post-Treatment |
|
|
133 | (2) |
|
6.4.2 Restructuring Data Sets by Using a Multi-Dimensional Array |
|
|
135 | (1) |
|
|
136 | (3) |
|
|
139 | (16) |
|
7.1 Vertically Combining Data Sets |
|
|
139 | (4) |
|
7.1.1 Concatenating Data Sets |
|
|
139 | (3) |
|
7.1.2 Interleaving Data Sets |
|
|
142 | (1) |
|
7.2 Horizontally Combining Data Sets |
|
|
143 | (12) |
|
|
143 | (3) |
|
|
146 | (1) |
|
|
147 | (4) |
|
|
151 | (1) |
|
|
152 | (3) |
|
|
155 | (26) |
|
8.1 Introduction to Reading and Writing Text Files |
|
|
155 | (5) |
|
8.1.1 Steps for Reading Text Files |
|
|
155 | (2) |
|
8.1.2 Steps for Writing Text Files |
|
|
157 | (1) |
|
|
157 | (1) |
|
|
158 | (1) |
|
8.1.5 SAS Date and Time Values |
|
|
158 | (2) |
|
|
160 | (15) |
|
|
161 | (1) |
|
|
162 | (2) |
|
|
164 | (4) |
|
8.2.4 Modified List Input |
|
|
168 | (2) |
|
|
170 | (1) |
|
8.2.6 Creating Observations by Using the Line Pointer-Controls |
|
|
171 | (1) |
|
8.2.7 Creating Observations by Using Line-Hold Specifiers |
|
|
172 | (3) |
|
|
175 | (6) |
|
|
175 | (1) |
|
|
176 | (1) |
|
|
177 | (1) |
|
|
177 | (4) |
|
|
181 | (24) |
|
9.1 Introduction to Functions and CALL Routines |
|
|
181 | (4) |
|
|
181 | (1) |
|
|
182 | (2) |
|
9.1.3 Categories of Functions and CALL Routines |
|
|
184 | (1) |
|
9.2 Date and Time Functions |
|
|
185 | (5) |
|
9.2.1 Creating Date and Time Values |
|
|
185 | (2) |
|
9.2.2 Extracting Components from Date and Time Values |
|
|
187 | (1) |
|
9.2.3 Date and Time Interval Functions |
|
|
188 | (2) |
|
|
190 | (8) |
|
9.3.1 Functions for Changing Character Cases |
|
|
190 | (1) |
|
9.3.2 Functions for Concatenating Character Strings |
|
|
191 | (3) |
|
9.3.3 Functions for Searching, Exacting, and Replacing Character Strings |
|
|
194 | (4) |
|
9.4 Functions for Converting Variable Types |
|
|
198 | (7) |
|
|
198 | (3) |
|
|
201 | (2) |
|
|
203 | (2) |
|
10 Useful SAS® Procedures |
|
|
205 | (34) |
|
10.1 Using the SORT Procedure to Eliminate Duplicate Observations |
|
|
205 | (3) |
|
10.1.1 Eliminating Observations with Duplicate BY Values |
|
|
205 | (2) |
|
10.1.2 Eliminating Duplicate Observations |
|
|
207 | (1) |
|
10.2 Using the COMPARE Procedure to Compare the Contents of Two Data Sets |
|
|
208 | (7) |
|
10.2.1 Information Provided from PROC COMPARE |
|
|
209 | (3) |
|
10.2.2 Comparing Observations with Common ID Values |
|
|
212 | (3) |
|
10.3 Restructuring Data Sets Using the TRANSPOSE Procedure |
|
|
215 | (12) |
|
10.3.1 Transposing an Entire Data Set |
|
|
216 | (3) |
|
10.3.2 Introduction to Transposing BY Groups |
|
|
219 | (1) |
|
10.3.3 Where the ID Statement Does Not Work for Transposing BY Groups |
|
|
220 | (1) |
|
10.3.4 Where the ID Statement Is Essential for Transposing BY Groups |
|
|
221 | (1) |
|
10.3.5 Handling Duplicated Observations Using the LET Option |
|
|
222 | (2) |
|
10.3.6 Situations Requiring Two or More Transpositions |
|
|
224 | (3) |
|
10.4 Creating the User-Defined Format Using the FORMAT Procedure |
|
|
227 | (9) |
|
10.4.1 Creating User-Defined Formats |
|
|
228 | (5) |
|
10.4.2 Retrieving User-Defined Formats |
|
|
233 | (2) |
|
10.4.3 Creating Variables by Using User-Defined Formats |
|
|
235 | (1) |
|
10.5 Using the OPTIONS Procedure to Modify SAS System Options |
|
|
236 | (3) |
Exercises |
|
239 | (2) |
References |
|
241 | (2) |
Index |
|
243 | |