An array definition is in effect only for the duration of the DATA step. If you want to use
the same array in several DATA steps, you must redefine the array in each step. You can,
however, redefine the array with the same variables in a later DATA step by using a
macro variable. A macro variable is useful for storing the variable names that you need,
as shown in this example:
%let list=NC SC GA VA;
data one;
array state{*} &list;
more SAS statements
run;
data two;
array state{*} &list;
more SAS statements
run;
Variations on Basic Array Processing
Determining the Number of Elements in an Array Efficiently
The DIM function in the iterative DO statement returns the number of elements in a one-
dimensional array or the number of elements in a specified dimension of a
multidimensional array, when the lower bound of the dimension is 1. Use the DIM
function to avoid changing the upper bound of an iterative DO group each time you
change the number of elements in the array.
The form of the DIM function is as follows:
DIMn(array-name)
where n is the specified dimension that has a default value of 1.
You can also use the DIM function when you specify the number of elements in the
array with an asterisk. Here are some examples of the DIM function:
do i=1 to dim(days);
do i=1 to dim4(days) by 2;
DO WHILE and DO UNTIL Expressions
Arrays are often processed in iterative DO loops that use the array reference in a DO
WHILE or DO UNTIL expression. In this example, the iterative DO loop processes the
elements of the array named Trend.
data test;
array trend{5} x1-x5;
input x1-x5 y;
do i=1 to 5 while(trend{i}<y);
more SAS statements
end;
datalines;
data lines
;
572 Chapter 25 Array Processing

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.