<?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: Write specific values from a matrix to a data table in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Write-specific-values-from-a-matrix-to-a-data-table/m-p/423875#M3949</link>
    <description>&lt;P&gt;I've been able to figure this out:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= output_table out= output_table;
by Row_Order Column_Order;
quit;

proc iml;
use output_table;  /* parameterization table for matrix 3 (output table)*/
read all var {Column_Order Row_Order FieldName};
close;

idx = loc(FieldName ^= " ");

refNames = FieldName[idx];

A = {0.1 0.2 0.5, 0.2 0.4 0.6, 0.2 0.3 0.8}; /*A is the full matrix to write*/

C = A[idx];
C = t(C);
mattrib C colname=refNames;

print C;

create data_to_write from C[colname = refNames];
append from C; /** create data set **/
close data_to_write;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 28 Dec 2017 10:51:30 GMT</pubDate>
    <dc:creator>ss59</dc:creator>
    <dc:date>2017-12-28T10:51:30Z</dc:date>
    <item>
      <title>Write specific values from a matrix to a data table</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Write-specific-values-from-a-matrix-to-a-data-table/m-p/423825#M3948</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a nxn matrix (for simplicity assuming n=3) like following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
A = {0.1 0.2 0.5, 0.2 0.4 0.6, 0.2 0.3 0.8};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have another table - a reference table, which specifies which values from this nxn (n=3) matrix needs to be written to a new data table. that table is following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data output_table;
infile datalines dsd;
length FieldName $20 FieldSourceTable $20;
input Matrix_Id Row_Order Column_Order IsZero FieldName	FieldSourceTable;
datalines;
3,    1,   1,	1,	.,	.
3,    1,   2,	0,	result1,	table2
3,    1,   3,	0,	result2,	table2
3,    2,   1,	1,	.,		.
3,    2,   2,	0,	sum1,	table2
3,    2,   3,	0,	sum2,	table2
3,    3,   1,	0,	prod1,		table2
3,    3,   2,	0,	prod2,		table2
3,    3,   3,	1,	.,		.
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Assume the matrix A is my Matrix_ID 3. So, I need to create a new table called table 2 with the names specified in 'FieldName' column in the reference table and write specific values from the matrix to the table (e.g. (1,2)th element to the column 'result1').&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this specific example, the output should look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;result1&lt;/TD&gt;&lt;TD&gt;result2&lt;/TD&gt;&lt;TD&gt;sum1&lt;/TD&gt;&lt;TD&gt;sum2&lt;/TD&gt;&lt;TD&gt;prod1&lt;/TD&gt;&lt;TD&gt;prod2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;0.2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;0.5&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;0.4&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;0.6&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;0.2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;0.3&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I do this in iml? Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 03:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Write-specific-values-from-a-matrix-to-a-data-table/m-p/423825#M3948</guid>
      <dc:creator>ss59</dc:creator>
      <dc:date>2017-12-28T03:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Write specific values from a matrix to a data table</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Write-specific-values-from-a-matrix-to-a-data-table/m-p/423875#M3949</link>
      <description>&lt;P&gt;I've been able to figure this out:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= output_table out= output_table;
by Row_Order Column_Order;
quit;

proc iml;
use output_table;  /* parameterization table for matrix 3 (output table)*/
read all var {Column_Order Row_Order FieldName};
close;

idx = loc(FieldName ^= " ");

refNames = FieldName[idx];

A = {0.1 0.2 0.5, 0.2 0.4 0.6, 0.2 0.3 0.8}; /*A is the full matrix to write*/

C = A[idx];
C = t(C);
mattrib C colname=refNames;

print C;

create data_to_write from C[colname = refNames];
append from C; /** create data set **/
close data_to_write;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Dec 2017 10:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Write-specific-values-from-a-matrix-to-a-data-table/m-p/423875#M3949</guid>
      <dc:creator>ss59</dc:creator>
      <dc:date>2017-12-28T10:51:30Z</dc:date>
    </item>
  </channel>
</rss>

