Processing Variables with Arrays |
Creating One-Dimensional
Arrays |
Understanding SAS Arrays
A SAS array is a temporary grouping of SAS variables under a single name. An array exists only for the duration of the DATA step. |
One reason for using an array is to reduce the number of statements required
to process variables. For example, in the DATA step below, the values of
seven data set variables are converted from Fahrenheit to Celsius temperatures.
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; As you can see, 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; set master.temps; array wkday(7) mon tue wed thr fri sat sun; do i=1 to 7; wkday(i)=5*(wkday(i)-32)/9; end; run; You learn other uses for arrays as you continue through this lesson. |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.