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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.