Chapter 20
BY-Group Processing in the DATA
Step
Definitions for BY-Group Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
Syntax for BY-Group Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
Understanding BY Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
BY Groups with a Single BY Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
BY Groups with Multiple BY Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
Invoking BY-Group Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
Determining Whether the Data Requires Preprocessing for
BY-Group Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Preprocessing Input Data for BY-Group Processing . . . . . . . . . . . . . . . . . . . . . . . . 453
Sorting Observations for BY-Group Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Indexing for BY-Group Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
How the DATA Step Identifies BY Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
Processing Observations in a BY Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
Using a Name Literal as the BY-Group Variable . . . . . . . . . . . . . . . . . . . . . . . . . . 454
How SAS Determines FIRST.variable and LAST.variable . . . . . . . . . . . . . . . . . . 455
Example 1: Grouping Observations by State, City, ZIP code, and Street . . . . . . . 455
Example 2: Grouping Observations by City, State, ZIP code, and Street . . . . . . . 457
Example 3: A Change Affecting FIRST.variable . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Processing BY-Groups in the DATA Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
Processing BY-Groups Conditionally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Data Not in Alphabetic or Numeric Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
Data Grouped by Formatted Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
Example 1: Using GROUPFORMAT with Formats . . . . . . . . . . . . . . . . . . . . . . . 461
Example 2: Using GROUPFORMAT with Formats . . . . . . . . . . . . . . . . . . . . . . . 461
Definitions for BY-Group Processing
BY-group processing
is a method of processing observations from one or more SAS data sets that are
grouped or ordered by values of one or more common variables. The most common
use of BY-group processing in the DATA step is to combine two or more SAS data
sets. To do this, you use the BY statement with a SET, MERGE, MODIFY, or
UPDATE statement.
449
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.236.27