Chapter 18
DATA Step Processing
Why Use a DATA Step? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Overview of DATA Step Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Flow of Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
The Compilation Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
The Execution Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Processing a DATA Step: A Walk-through . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Sample DATA Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Creating the Input Buffer and the Program Data Vector . . . . . . . . . . . . . . . . . . . . 383
Reading a Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Writing an Observation to the SAS Data Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Reading the Next Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
When the DATA Step Finishes Executing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
About DATA Step Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
The Default Sequence of Execution in the DATA Step . . . . . . . . . . . . . . . . . . . . . 387
Changing the Default Sequence of Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Step Boundary—How to Know When Statements Take Effect . . . . . . . . . . . . . . . 390
What Causes a DATA Step to Stop Executing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
About Creating a SAS Data Set with a DATA Step . . . . . . . . . . . . . . . . . . . . . . . . 393
Creating a SAS Data File or a SAS View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Sources of Input Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Reading Raw Data: Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Reading Data from SAS Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
Generating Data from Programming Statements . . . . . . . . . . . . . . . . . . . . . . . . . . 396
Writing a Report with a DATA Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
Example 1: Creating a Report without Creating a Data Set . . . . . . . . . . . . . . . . . . 397
Example 2: Creating a Customized Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Example 3: Creating an HTML Report Using ODS and the DATA Step . . . . . . . 402
The DATA Step and ODS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
DATA Step Processing Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
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
379

Get SAS 9.4 Language Reference, 3rd 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.