<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating an average matrix from four individual matrices of same size in SAS / IML in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-an-average-matrix-from-four-individual-matrices-of-same/m-p/334599#M3293</link>
    <description>&lt;P&gt;Turns out the code above works. I had a seperate issue in my dataset. I'll leave the question up in case somebody else wants to do something simillar in the future.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Feb 2017 09:30:40 GMT</pubDate>
    <dc:creator>martinreindl</dc:creator>
    <dc:date>2017-02-21T09:30:40Z</dc:date>
    <item>
      <title>Creating an average matrix from four individual matrices of same size in SAS / IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-an-average-matrix-from-four-individual-matrices-of-same/m-p/334589#M3292</link>
      <description>&lt;P&gt;I am using IML/SAS in SAS Enterprise Guide for the first time, and want to do the following:&lt;BR /&gt;&lt;BR /&gt;1.&amp;nbsp; Read some datasets into IML matrices&lt;BR /&gt;2.&amp;nbsp; Average the matrices&lt;BR /&gt;3.&amp;nbsp; Turn the resulting IML matrix back into a SAS data set&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;    data_set0:     d_1    d_2    d_3
                   1      2      3
                   4      5      6
                   7      8      9&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;I proceed as follows:&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; 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; &lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;I've been trying loads of stuff, but nothing seems to work for me. The error I currently get reads:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;ERROR: Matrix matrix_sum has not been set to a value&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;What am I doing wrong? Thanks up front for the help.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 09:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-an-average-matrix-from-four-individual-matrices-of-same/m-p/334589#M3292</guid>
      <dc:creator>martinreindl</dc:creator>
      <dc:date>2017-02-21T09:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an average matrix from four individual matrices of same size in SAS / IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-an-average-matrix-from-four-individual-matrices-of-same/m-p/334599#M3293</link>
      <description>&lt;P&gt;Turns out the code above works. I had a seperate issue in my dataset. I'll leave the question up in case somebody else wants to do something simillar in the future.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 09:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-an-average-matrix-from-four-individual-matrices-of-same/m-p/334599#M3293</guid>
      <dc:creator>martinreindl</dc:creator>
      <dc:date>2017-02-21T09:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an average matrix from four individual matrices of same size in SAS / IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-an-average-matrix-from-four-individual-matrices-of-same/m-p/334600#M3294</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data_set0;
   input d_1 d_2 d_3;
   datalines;
1      2      3
4      5      6
7      8      9
;

data data_set1;
   input d_1 d_2 d_3;
   datalines;
1      2      3
4      5      6
7      8      9
;

data data_set2;
   input d_1 d_2 d_3;
   datalines;
1      2      3
4      5      6
7      8      9
;

data data_set3;
   input d_1 d_2 d_3;
   datalines;
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_set0;
        READ all var _ALL_ into data_set0_matrix[colname=varNames];
        CLOSE data_set_0;
 
        USE data_set1;
        READ all var _ALL_ into data_set1_matrix[colname=varNames];
        CLOSE data_set_1;

        USE data_set2;
        READ all var _ALL_ into data_set2_matrix[colname=varNames];
        CLOSE data_set_2;

        USE data_set3;
        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; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Just minor corrections will make your code work as above &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT: I see you made it work already. Thumbs up &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 09:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-an-average-matrix-from-four-individual-matrices-of-same/m-p/334600#M3294</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-02-21T09:33:07Z</dc:date>
    </item>
  </channel>
</rss>

