0

I am using IML/SAS in SAS Enterprise Guide for the first time, and want to do the following:

  1. Read some datasets into IML matrices
  2. Average the matrices
  3. Turn the resulting IML matrix back into a SAS data set

My input data sets look something like the following (this is dummy data - the actual sets are larger). The format of the input data sets is also the format I want from the output data sets.

data_set0:     d_1    d_2    d_3
               1      2      3
               4      5      6 
               7      8      9 

I proceed as follows:

proc iml;
    /* set the names of the migration matrix columns */
    varNames = {"d_1","d_2","d_3"};

    /* 1. transform input data set into matrix 
    USE data_set_0;
    READ all var _ALL_ into data_set0_matrix[colname=varNames];
    CLOSE data_set_0;

    USE data_set_1;
    READ all var _ALL_ into data_set1_matrix[colname=varNames];
    CLOSE data_set_1;

    USE data_set_2;
    READ all var _ALL_ into data_set2_matrix[colname=varNames];
    CLOSE data_set_2;

    USE data_set_3;
    READ all var _ALL_ into data_set3_matrix[colname=varNames];
    CLOSE data_set_3;

    /* 2. find the average matrix */
    matrix_sum = (data_set0_matrix + data_set1_matrix + 
                  data_set2_matrix + data_set3_matrix)/4;

    /* 3. turn the resulting IML matrix back into a SAS data set */ 
    create output_data from matrix_sum[colname=varNames];
    append from matrix_sum; 
    close output_data; 
 quit; 

I've been trying loads of stuff, but nothing seems to work for me. The error I currently get reads:

ERROR: Matrix matrix_sum has not been set to a value

What am I doing wrong? Thanks up front for the help.

Martin Reindl
  • 989
  • 2
  • 15
  • 33

1 Answers1

0

The above code works. In the full version of this code (this is simplified for readability) I had misnamed one of my variables.

I'll leave the question up in case somebody else wants to use SAS / IML to find an average matrix.

Martin Reindl
  • 989
  • 2
  • 15
  • 33
  • This isn't a helpful answer right now. If you want it to be helpful, describe the separate issue (not necessarily in detail, but the kind of issue), so someone else with the same problem can see how to identify the issue. – Joe Feb 21 '17 at 15:20
  • I just edited my answer. Not sure what more I can say. The code above solves the problem of creating an average matrix from four individual matrices of same size in SAS / IML. – Martin Reindl Feb 22 '17 at 15:18
  • If that's all you can say, then I'd close/delete the question; this isn't really helpful to anyone. If you want to show how to find an average matrix, ask a new question (or reword your question) to ask that, and then post the above code as an answer. – Joe Feb 22 '17 at 17:18
  • Sounds like a plan. Will do. – Martin Reindl Feb 22 '17 at 20:44