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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.