Chapter 20
DATA Step Processing
Why Use a DATA Step? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Overview of DATA Step Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Flow of Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
The Compilation Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
The Execution Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Processing a DATA Step: A Walk-through . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Sample DATA Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Creating the Input Buffer and the Program Data Vector . . . . . . . . . . . . . . . . . . . . 415
Reading a Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
Writing an Observation to the SAS Data Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Reading the Next Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
When the DATA Step Finishes Executing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
About DATA Step Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
The Default Sequence of Execution in the DATA Step . . . . . . . . . . . . . . . . . . . . . 419
Changing the Default Sequence of Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Step Boundary—How to Know When Statements Take Effect . . . . . . . . . . . . . . . 422
What Causes a DATA Step to Stop Executing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
About Creating a SAS Data Set with a DATA Step . . . . . . . . . . . . . . . . . . . . . . . . . 425
Creating a SAS Data File or a SAS View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
Sources of Input Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
Reading Raw Data: Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
Reading Data from SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Generating Data from Programming Statements . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Writing a Report with a DATA Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Example 1: Creating a Report without Creating a Data Set . . . . . . . . . . . . . . . . . . 429
Example 2: Creating a Customized Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
Example 3: Creating an HTML Report Using ODS and the DATA Step . . . . . . . . 434
The DATA Step and ODS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
DATA Step Processing Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Why Use a DATA Step?
Using the DATA step is the primary method for creating a SAS data set with Base SAS
software. A DATA step is a group of SAS language statements that begin with a DATA
411

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.