Invoking BY-Group Processing
To create BY groups, you use the BY statement in one of two ways:
DATA step
PROC step (For information about BY-group processing with procedures, see
“Creating Titles That Contain BY-Group Information ” in Base SAS Procedures
Guide.)
The following DATA step program uses the SET statement to combine observations
from three SAS data sets by interleaving the files. The data is ordered by State City and
Zip.
data all_sales;
set region1 region2 region3;
by State City Zip;
more SAS statements
run;
Determining Whether the Data Requires
Preprocessing for BY-Group Processing
Before you perform BY-group processing on multiple data sets using the SET, MERGE,
and UPDATE statements, you must check the data to determine whether it requires
preprocessing. They require no preprocessing if the observations in all of the data sets
occur in one of the following patterns:
ascending or descending numeric order
ascending or descending character order
not alphabetically or numerically ordered, but grouped in some way, such as by
calendar month or by a formatted value
If the observations are not in the order that you want, you must either sort the data set or
create an index for it before using BY-group processing.
If you use the MODIFY statement in BY-group processing, you do not need to presort
the input data. Presorting, however, can make processing more efficient and less costly.
You can use PROC SQL views in BY-group processing. For complete information, see
SAS SQL Procedure User’s Guide.
Note: SAS/ACCESS Users: If you use SAS views or librefs, see SAS/ACCESS for
Relational Databases: Reference for information about using BY groups in your
SAS programs.
464 Chapter 22 BY-Group Processing in the DATA Step

Get SAS 9.4 Language Reference, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.