0

我是第一次在 SAS Enterprise Guide 中使用 IML/SAS,并且想要执行以下操作:

  1. 将一些数据集读入 IML 矩阵
  2. 平均矩阵
  3. 将生成的 IML 矩阵转回 SAS 数据集

我的输入数据集如下所示(这是虚拟数据 - 实际数据集更大)。输入数据集的格式也是我想要的输出数据集的格式。

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

我进行如下操作:

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; 

我一直在尝试很多东西,但似乎没有什么对我有用。我目前得到的错误是:

ERROR: Matrix matrix_sum has not been set to a value

我究竟做错了什么?预先感谢您的帮助。

4

1 回答 1

0

上面的代码有效。在这段代码的完整版本中(为了便于阅读,这被简化了)我错误地命名了我的一个变量。

如果其他人想使用 SAS / IML 来找到平均矩阵,我会留下这个问题。

于 2017-02-21T09:29:24.890 回答