## MultiArray

Occasional Contributor
Posts: 10

# MultiArray

Array multi{1:2, 2}(1,2);

Do i=1 to 2;

Do j=1 to 2;

Output=multi{I,j};

What is the corresponding values of i, j, and output.

Someone gives the answer: A 2*2 multi-array, only two initial values, so :

i   j  output

1  1  1

1  2  2

2  1   .

2  2   .

Could anybody explain how to get this result?

Super User
Posts: 6,781

## Re: MultiArray

"Someone" gave you the correct answer.  But there's a lot to explain.  Why don't you begin by explaining the parts of the ARRAY statement that you already understand.  Then we can fill in the remainder without having to explain things that you already know.

Posts: 1,345

## Re: MultiArray

Multi-dimensional arrays are stored in row-major order.  I.e all the elements of the first row precede the 2nd row, which precedes the 3rd row, etc.  And the first array index is the row index, the second is the column index.

Your  statement

array{1:2,2}

is the same as

array{2,2};

which is 2 rows of 2-elements each.

The 2 initial values (1,2) are assigned to the first two elements of X, translating to elements  {1,1} and {1,2}.

If you run this program you will print out the memory addresses of each element, confirming the row-major order of array storage.

``````data _null_;
array x{2,2} (1,2);
run;``````

Note that the addresses are "little-endian", i.e. the least significant byte (i.e. the least significant pair of hexadecimal digits) is the leftmost.  The addresses in my machine came out as:

``````9    data _null_;
10     array x{2,2} (1,2);
WARNING: Partial value initialization of the array x.