Contents
About This Book...................................................................................... vii
About The Author ..................................................................................... xi
Acknowledgments.................................................................................. xiii
Preface ....................................................................................................xv
Chapter 1: An Overview of Hash Objects.................................................... 1
What Are Hash Objects? ............................................................................................................... 2
Introducing a Simple Hash Object Application........................................................................... 2
Chapter 2: Hash Object Terminology and Concepts ................................... 7
What Is a SAS Hash Object?......................................................................................................... 7
Defining Terms Associated with Hash Objects .......................................................................... 8
Writing Code That Works with Hash Objects.............................................................................. 9
Understanding How SAS Stores Hash Objects in Memory .....................................................10
Understanding How Long Hash Objects Persist......................................................................11
Specifying the Contents of Hash Objects..................................................................................11
Initializing Variables in a DATA Step That Contains a Hash Object........................................14
Illustrating How the Program Data Vector Connects DATA Step Variables
and Hash Object Items................................................................................................................15
Chapter 3: Basic Hash Object Applications..............................................25
Using a Hash Object As a Lookup Table...................................................................................26
Defining a Hash Object................................................................................................................26
Finding Key Values in a Hash Object.........................................................................................28
Defining the Key Structure in a Hash Object ............................................................................30
Understanding How the FIND and CHECK Methods Alter the Values of DATA Step
Variables and Hash Object Data Items......................................................................................30
Application Example: Verifying Presence of Key Values .........................................................33
Application Example: Returning Data Items from a Hash Object...........................................36
Application Example: Defining the Key Value During Processing of the DATA Step............39
Application Example: Searching for a Key Value in Multiple Hash Objects...........................41
Application Example: Combining Data from Multiple Sources...............................................44
Using Multiple Key Items to Look Up Data ...............................................................................49
Traversing Hash Objects.............................................................................................................53
Specifying a Hash Iterator Object..............................................................................................53
Understanding the Methods That Control Traversal of a Hash Object..................................54
Illustrating How the Hash Iterator Object Traverses a Hash Object......................................55
Application Example: Traversing a Hash Object from Beginning to End...............................59
Application Example: Linking Hierarchically Related Data Sets.............................................62
Application Example: Performing a Fuzzy Merge Using a Hash Iterator Object...................66
Chapter 4: Creating Data Sets from Hash Objects and Updating
Contents of Hash Objects.......................................................71
Creating a Data Set from a Hash Object...................................................................................72
Adding, Modifying, and Removing Data from a Hash Object..................................................73
Defining the Key Structure in a Hash Object ............................................................................74
Understanding How to Specify the KEY and DATA Argument Tags ......................................75
Identifying the Variables That the OUTPUT Method Writes to a Data Set.............................77
Understanding the Interaction between DATA Step Variables and Hash Object
Data Items When Replacing Data in a Hash Object................................................................. 78
Replacing Key Item Values When a Key Item Is Also a Data Item..........................................80
Comparing the DATA Statement and the OUTPUT Method....................................................83
Application Example: Finding the Unique Values of a Variable in a Data Set........................87
Application Example: Ordering Observations by Variables Not Saved to a Data Set
Created from a Hash Object.......................................................................................................90
Application Example: Using Hash Objects to Apply Transactions to
Master Data Sets—Part 1............................................................................................................92
Application Example: Using Hash Objects to Apply Transactions to
Master Data Sets—Part 2............................................................................................................97
Application Example: Summarizing Data with the Hash Iterator Object.............................102
Application Example: Summarizing Hierarchically Related Data .........................................106
Chapter 5: Hash Objects with Multiple Sets of Data Items per
Key Value.............................................................................113
Understanding the Concepts of Duplicate Key Values and Multiple Sets
of Data Items per Key Value in a Hash Object........................................................................114
Defining Hash Objects That Process Multiple Sets of Data Items per Key Value...............115
Illustrating How the MULTIDATA and DUPLICATE Argument Tags Affect Hash
Object Processing......................................................................................................................117
Understanding the Methods That Look for Multiple Sets of Data Items per Key ...............121
Understanding How SAS Stores Multiple Sets of Data Items per Key................................. 123
Comparing Retrieval of Data from a Hash Object That Allows Multiple
Sets of Data Items per Key Value to a Hash Iterator Object.................................................123
Modifying Data in a Hash Object That Allows Multiple Sets of Data Items per Key Value 129
Summarizing Data in Hash Objects That Allow Multiple Sets of Data Items per
Key Value ....................................................................................................................................143
Application Example: Summarizing and Sorting a Data Set..................................................144
Application Example: Creating Data Sets Based on a Series of Observations...................147
Application Example: Creating a Data Set That Contains All Combinations
of Specific Variables When the Number of Combinations Is Large......................................151
Application Example: Linking Hierarchically Related Data Using a Hash Object
That Allows Multiple Sets of Data Items per Key Value.........................................................154
Chapter 6: Managing Hash Objects........................................................159
Creating, Deleting, and Clearing Hash Objects During Execution of a DATA Step............159
Determining the Number of Items in a Hash Object ..............................................................164
Application Example: Creating a Data Set for Each BY Group.............................................166
Comparing Two Hash Objects..................................................................................................170
Specifying Memory Structure Usage of a Hash Object.........................................................174
Determining the Size of an Entry in a Hash Object................................................................174
Index.....................................................................................................181
· · · · · · (
收起)