BookmarkSubscribeRSS Feed
zana
Calcite | Level 5

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.2010.1047.66-6.77
-2.096.142.54-1.06
0.362.36-1.051.8
0.89-0.36-1.25-0.08
1.202.360.65-0.19
0.44-0.470.541.25
-0.041.78-0.151.36
0.13-0.541.231.11

Please let me i show that as a simple way.

1234
5678
9101112
13141516
17181920
21222324
25262728
29303132

Now, i would like to create three submatrix (4*4) that they should be like these;

1st submatrix;

1234
2567
3689
47910

2nd submatrix;

11121314
12151617
13161819
14171920

and

...

How could i do it?


Many thanks!

4 REPLIES 4
mohamed_zaki
Barite | Level 11

What is formula or the method you want to use to extract the sub-matrix?

CTorres
Quartz | Level 8

I assume that

3rd submatrix:

21222324
22252627
23262829
24272930

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?

zana
Calcite | Level 5

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).

1234567
891011121314
15161718192021
22232425262728
29303132333435
36373839404142
43444546474849
50515253545556
57585960616263
64656667686970
71727374757677
78798081828384
85868788899091
92939495969798
99100101102103104105
106107108109110111112
113114115116117118.

For this table i need a program that extract submatrix as 8*8.

Thanks for your kind.

CTorres
Quartz | Level 8

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 630 views
  • 0 likes
  • 3 in conversation