SAS Consulting, Department of Statistics
This is an example of a simple array. Arrays are used with do loops to process a list of variables in the same manner.
In this example the array name is zero. The variable list includes x1,x2,x3,x4 and x5.
This array changes all missing values to zeros in the variables named in the array statement.
data original;
input x1-x5;
cards;
9 8 7 8 .
8 7 6 . 9
. . 9 7 6
proc print;
Title 'Original Data';
run;
data modified; set original;
array zero x1-x5;
do over zero;
if zero=. then zero=0;
end;
proc print;
Title 'Data modified with arrray and do loop';
run;
*** Explicitly subscripted array;
DATA ftoc2;
INPUT month $ f1-f7;
ARRAY f{7} f1-f7;
ARRAY c{7} c1-c7;
DO i=1 to 7;
c{i}=( f{i}-32 )*5/9;
END;
FORMAT c1-c7 4.1;
CARDS;
aug 94 98 99 98 99 96 91 90 88 89
sept 93 92 87 87 89 90 91 92 82 80
;
PROC PRINT;
title1 'DATA; FTOC2';
title2 'Explicit Array Example';
RUN;
*** Implicitly subscripted array;
DATA ftoc;
INPUT month $ f1-f7;
ARRAY f(i) f1-f7;
ARRAY c(i) c1-c7;
DO over f;
c=(f-32)*5/9;
END;
FORMAT c1-c7 4.1;
CARDS;
aug 94 98 99 98 99 96 91 90 88 89
sept 93 92 87 87 89 90 91 92 82 80
;
PROC PRINT;
TITLE1 'DATA: FTOC';
TITLE2 'Implicit Array Example';
run;
TITLE;
RUN;