Dear all,
I want to create a two dimensional array from my dataset.
Here is my sample dataset
And I would like to create a 2 dimensional array like this
Hi and welcome to the SAS Communities 🙂
You can do like this
data have;
input row col num;
datalines;
1 1 1
1 2 2
1 3 3
2 1 4
2 2 5
2 3 6
3 1 7
3 2 8
3 3 9
;
data want;
set have end=lr;
array MyArray {3, 3} _temporary_;
MyArray[row, col]=num;
/* Verify that the values are correctly assigned */
if lr;
do i=1 to 3;
do j=1 to 3;
put (MyArray[i, j])(=);
end;
end;
run;
This prints
Hi and welcome to the SAS Communities 🙂
You can do like this
data have;
input row col num;
datalines;
1 1 1
1 2 2
1 3 3
2 1 4
2 2 5
2 3 6
3 1 7
3 2 8
3 3 9
;
data want;
set have end=lr;
array MyArray {3, 3} _temporary_;
MyArray[row, col]=num;
/* Verify that the values are correctly assigned */
if lr;
do i=1 to 3;
do j=1 to 3;
put (MyArray[i, j])(=);
end;
end;
run;
This prints
Do you have IML ?
data have;
input row col num;
datalines;
1 1 1
1 2 2
1 3 3
2 1 4
2 2 5
2 3 6
3 1 7
3 2 8
3 3 9
;
proc iml;
use have;
read all var {row col num};
close;
x=num||row||col;
have=full(x);
print have;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.