Processing Variables with Arrays |
Creating Multidimensional
Arrays |
Defining a Multidimensional Array
To define a multidimensional array, you specify the number of elements in each dimension, separated by a comma. This ARRAY statement defines a two-dimensional array: array new(3,4) x1-x12; In a two-dimensional array, the two dimensions can be thought of as a table of rows and columns. |
array new(r,c) x1-x12;
|
|
The first dimension in the ARRAY statement specifies the number of rows. |
V array new(3,4) x1-x12; |
|
The second dimension specifies the number of columns. |
V array new(3,4) x1-x12; |
|
You can reference any element of the array by specifying the two dimensions.
In the example below, you can perform an action on the variable
x7 by specifying the array reference new(2,3) .
You can easily locate the array element in the table by finding the row (2),
then the column (3). |
array new(3,4) x1-x12; new(2,3)=0; |
|
When you define a two-dimensional array, the array elements are grouped
in the order they are listed in the ARRAY statement. For instance, the array
elements x1 through x4 can be thought of as the
first row of the table. |
V V V V array new(3,4) x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12; |
x1 | x2 | x3 | x4 |
x5 | x6 | x7 | x8 |
x9 | x10 | x11 | x12 |
The elements x5 through x8 become the second
row of the table, and so on.
V V V V array new(3,4) x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12; |
x1 | x2 | x3 | x4 |
x5 | x6 | x7 | x8 |
x9 | x10 | x11 | x12 |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.