I need to create a square matrix (let's call it SQUARE_M) where the rows represent a certain variable (let's call it Var_A), the columns, another variable (Var_B), and their intersection, a certain value resulting from a combination of the two variables. Each variable can have m values, so my matrix needs to have m rows and m columns.
Currently, I have a matrix (let's call it CURRENT) with m**2 rows and 3 columns (Var_A, Var_B, and, for each combination of the two, the resulting value in Var_C). I intend to get the matrix into a square shape (as described above) as follows:
1. Sort current matrix by Var_A, then by Var_B;
2. Create a square matrix, populated only with 1's so far:
SQUARE_M=j (m, m+1, 1); *The extra column is for holding the value of VAR_A from the CURRENT matrix;
What I'm not sure of, though, is the exact IML syntax for the two steps below:
3. Loop through VAR_A in CURRENT and write each unique value into column 1 in SQUARE_M, in the order in which they are found.
For each unique value in VAR_A, write the corresponding values in VAR_C into the relevant row in SQUARE_M, roughly like this:
m = [number of rows and columns in my data];
r_new_row = 1; * row in new matrix;
c_new_column = 1; * column in new matrix;
while c_new_column <= m:
(write the figure from CURRENT to [m_square_row, m_square_column]);
c_square_column +=1;
r_square_row +=1;
quit;
Also, am I right that, when counting rows or columns, IML begins with 1 rather than 0?
... View more