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?
"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.
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);
add1_1=addrlong(x{1,1});
add1_2=addrlong(x{1,2});
add2_1=addrlong(x{2,1});
add2_2=addrlong(x{2,2});
put (add:) (=$hex16. /);
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.
11 add1_1=addrlong(x{1,1});
12 add1_2=addrlong(x{1,2});
13 add2_1=addrlong(x{2,1});
14 add2_2=addrlong(x{2,2});
15 put (add:) (=$hex16. /);
16 run;
add1_1=9010682A00000000
add1_2=9810682A00000000
add2_1=A010682A00000000
add2_2=A810682A00000000
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.