An array is
a temporary grouping of SAS variables that are arranged in a particular
order and identified by an array name. Here are several facts about
arrays.
-
Arrays exist only for the duration
of the current DATA step.
-
Arrays are referenced by the array
name and a subscript.
-
The array name is not a variable.
An array is a convenient
way of temporarily identifying a group of variables. Arrays are often
referenced in DO loops because more than one element in an array must
be processed.
One reason for using
an array is to reduce the number of statements that are required for
processing variables. For example, in the DATA step below, the values
of seven data set variables are converted from Fahrenheit to Celsius.
data work.report;
set master.temps;
mon=5*(mon-32)/9;
tue=5*(tue-32)/9;
wed=5*(wed-32)/9;
thr=5*(thr-32)/9;
fri=5*(fri-32)/9;
sat=5*(sat-32)/9;
sun=5*(sun-32)/9;
run;
The assignment statements
perform the same calculation on each variable in this series of statements.
Only the name of the variable changes in each statement.
By grouping the variables
into a one-dimensional array, you can process the variables in a DO
loop. You use fewer statements, and the DATA step program is more
easily modified or corrected.
data work.report(drop=day);
set master.temps;
array wkday{7} mon tue wed thr fri sat sun;
do day=1 to 7;
wkday{day}=5*(wkday{day}-32)/9;
end;
run;