Hello,
Currently i have problem for convert some submatrix from an output solution file. The one of output table (this output file contains 4000 table like as follows) is represented as the follows:
3.201 | 0.104 | 7.66 | -6.77 |
-2.09 | 6.14 | 2.54 | -1.06 |
0.36 | 2.36 | -1.05 | 1.8 |
0.89 | -0.36 | -1.25 | -0.08 |
1.20 | 2.36 | 0.65 | -0.19 |
0.44 | -0.47 | 0.54 | 1.25 |
-0.04 | 1.78 | -0.15 | 1.36 |
0.13 | -0.54 | 1.23 | 1.11 |
Please let me i show that as a simple way.
1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 |
Now, i would like to create three submatrix (4*4) that they should be like these;
1st submatrix;
1 | 2 | 3 | 4 |
2 | 5 | 6 | 7 |
3 | 6 | 8 | 9 |
4 | 7 | 9 | 10 |
2nd submatrix;
11 | 12 | 13 | 14 |
12 | 15 | 16 | 17 |
13 | 16 | 18 | 19 |
14 | 17 | 19 | 20 |
and
...
How could i do it?
Many thanks!
What is formula or the method you want to use to extract the sub-matrix?
I assume that
3rd submatrix:
21 | 22 | 23 | 24 |
22 | 25 | 26 | 27 |
23 | 26 | 28 | 29 |
24 | 27 | 29 | 30 |
I also assume that table is a sas dataset:
data table;
input v1-v4;
cards;
3.201 0.104 7.66 -6.77
-2.09 6.14 2.54 -1.06
0.36 2.36 -1.05 1.8
0.89 -0.36 -1.25 -0.08
1.2 2.36 0.65 -0.19
0.44 -0.47 0.54 1.25
-0.04 1.78 -0.15 1.36
0.13 -0.54 1.23 1.11
;
run;
I developed the following solution that creates 3 SAS datasets: Submatrix1, Submatrix2 and Submatrix3:
data submatrix1(keep=colA:)
submatrix2(keep=colB:)
submatrix3(keep=colC:);
array vector(32);
array MatrixA(4,4);
array MatrixB(4,4);
array MatrixC(4,4);:
array ColA(4);
array ColB(4);
array ColC(4);
retain x 0;
do until (eof);
set table end=eof;
vector(x+1)=v1;
vector(x+2)=v2;
vector(x+3)=v3;
vector(x+4)=v4;
x+4;
end;
do i=1 to 4;
do j=1 to 4;
if min(i,j)=1 and (i=1 or j=1) then MatrixA(i,j)=max(i,j);
else if min(i,j)=2 and (i=2 or j=2) then MatrixA(i,j)=i+j+1;
else MatrixA(i,j)=i+j+2;
end;
end;
do i=1 to 4;
do j=1 to 4;
MatrixB(i,j)=MatrixA(i,j)+10;
MatrixC(i,j)=MatrixA(i,j)+20;
end;
end;
do i=1 to 4;
do j=1 to 4;
n=MatrixA(i,j);
colA(j)=vector(n);
n=MatrixB(i,j);
colB(j)=vector(n);
n=MatrixC(i,j);
colC(j)=vector(n);
end;
output submatrix1;
output submatrix2;
output submatrix3;
end;
run;
Is this what you need?
Thank you so much. For this example your code was true. Dear Torres, but when i try for another table file (rows=17; columns=7) it was more error. Please say me how can i run for this table (as follows).
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 |
43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 |
57 | 58 | 59 | 60 | 61 | 62 | 63 |
64 | 65 | 66 | 67 | 68 | 69 | 70 |
71 | 72 | 73 | 74 | 75 | 76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 |
85 | 86 | 87 | 88 | 89 | 90 | 91 |
92 | 93 | 94 | 95 | 96 | 97 | 98 |
99 | 100 | 101 | 102 | 103 | 104 | 105 |
106 | 107 | 108 | 109 | 110 | 111 | 112 |
113 | 114 | 115 | 116 | 117 | 118 | . |
For this table i need a program that extract submatrix as 8*8.
Thanks for your kind.
I do not understand the relation between the first matrix and the submatrixes you want to produce so you are right: Mi program does not work for the general case (witch I dont understand).
Anyway, I developed a Logic to populate any submatrix NxN from an initial value on. See this same entry in SAS/IML Software and Matrix computations.
CTorres
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: