Chapter 25
Array Processing
Definitions for Array Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
A Conceptual View of Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
One-Dimensional Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
Two-Dimensional Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
Syntax for Defining and Referencing an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
Processing Simple Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
Grouping Variables in a Simple Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
Using a DO Loop to Repeat an Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
Using a DO Loop to Process Selected Elements in an Array . . . . . . . . . . . . . . . . . 569
Selecting the Current Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570
Defining the Number of Elements in an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
Rules for Referencing Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
Variations on Basic Array Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572
Determining the Number of Elements in an Array Efficiently . . . . . . . . . . . . . . . . 572
DO WHILE and DO UNTIL Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572
Using Variable Lists to Define an Array Quickly . . . . . . . . . . . . . . . . . . . . . . . . . . 573
Multidimensional Arrays: Creating and Processing . . . . . . . . . . . . . . . . . . . . . . . . 573
Grouping Variables in a Multidimensional Array . . . . . . . . . . . . . . . . . . . . . . . . . 573
Using Nested DO Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
Specifying Array Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575
Identifying Upper and Lower Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575
Determining Array Bounds: LBOUND and HBOUND Functions . . . . . . . . . . . . 576
When to Use the HBOUND Function Instead of the DIM Function . . . . . . . . . . . 576
Specifying Bounds in a Two-Dimensional Array . . . . . . . . . . . . . . . . . . . . . . . . . . 577
Examples of Array Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
Example 1: Using Character Variables in an Array . . . . . . . . . . . . . . . . . . . . . . . . 577
Example 2: Assigning Initial Values to the Elements of an Array . . . . . . . . . . . . . 578
Example 3: Creating an Array for Temporary Use in the Current DATA Step . . . 579
Example 4: Performing an Action on All Numeric Variables . . . . . . . . . . . . . . . . 580
565

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

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