<?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: convert 3 column dataset into matrix in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419522#M3889</link>
    <description>&lt;P&gt;Another question:&lt;/P&gt;
&lt;P&gt;Look at the output of the following call to PROC FREQ. Is this what you want, except you want it in a symmetric matrix in SAS/IML?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=class;
   tables ticker1*ticker2 / norow nocol nocum nopercent;
   weight Position;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 08 Dec 2017 10:53:26 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2017-12-08T10:53:26Z</dc:date>
    <item>
      <title>convert 3 column dataset into matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419409#M3885</link>
      <description>&lt;P&gt;I have the following input:&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;Ticker1&lt;/TD&gt;&lt;TD&gt;Ticker2&lt;/TD&gt;&lt;TD&gt;Edge&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;EFG&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;NOM&lt;/TD&gt;&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t;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;EFG&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;NOM&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;99&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XYZ&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;99&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;QQQ&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How should I do this? the above is just to give an idea. My input dataset is:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.CLASS;
  infile datalines dsd truncover;
  input ticker1:$10. ticker2:$10. edge:32.;
datalines4;
ABC,EFG,3&lt;BR /&gt;ABC,NOM,10&lt;BR /&gt;ABC,XYZ,50&lt;BR /&gt;EFG,NOM,2&lt;BR /&gt;EFG,XYZ,0&lt;BR /&gt;EFG,QQQ,2&lt;BR /&gt;XYZ,QQQ,6&lt;BR /&gt;XYZ,NOM,99
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I cut this down to 15 obs but my dataset has 500 and the ticker set are the same for ticker1 and ticker2. Thus I would want a n x n matrix.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 22:47:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419409#M3885</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2017-12-10T22:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: convert 3 column dataset into matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419521#M3888</link>
      <description>&lt;P&gt;To clarify:&lt;/P&gt;
&lt;P&gt;1. You say "the ticker symbols are the same for ticker1 and ticker2." Does that mean that you have a long data set&amp;nbsp;that has (n x n) rows and you want to convert it to an (n x n) matrix? Or do you only have the upper triangular portion of the matrix, as shown in the little 3x3 example,&amp;nbsp;which has&amp;nbsp; 3 observation?&lt;/P&gt;
&lt;P&gt;2. In the second data set, do the cell counts from the Position variable? Is the Edge variable used at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your example, Ticker1 and Ticker2 do not have the same symbols. Please provide sample data that fits the problem you want to solve (or adjust your description of the problem)&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 10:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419521#M3888</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-12-08T10:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: convert 3 column dataset into matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419522#M3889</link>
      <description>&lt;P&gt;Another question:&lt;/P&gt;
&lt;P&gt;Look at the output of the following call to PROC FREQ. Is this what you want, except you want it in a symmetric matrix in SAS/IML?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=class;
   tables ticker1*ticker2 / norow nocol nocum nopercent;
   weight Position;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Dec 2017 10:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419522#M3889</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-12-08T10:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: convert 3 column dataset into matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419551#M3890</link>
      <description>&lt;P&gt;The&amp;nbsp;way to solve this problem depends on properties of the input data:&lt;/P&gt;
&lt;P&gt;1. Are the data sorted by Ticker1 Ticker2&amp;nbsp;?&lt;/P&gt;
&lt;P&gt;2. Are all joint levels represented? That is, do you have an observation for every possible pair?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the answers to (1) and (2) are both yes, then I think the following DATA step produces sample data that meets the conditions. The SAS/IML statement reads the data into the upper triangular portion of a matrix and then makes the matrix symmetric. The program uses &lt;A href="https://blogs.sas.com/content/iml/2012/09/17/filling-the-lower-and-upper-triangular-portions-of-a-matrix.html" target="_self"&gt;the ROW and COL function calls&lt;/A&gt;, which were introduced in SAS/IML 13.1 (SAS 9.4M1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
array c[5] $ ('A','B','C','D','E');
do i = 1 to dim(c);
   Var1 = c[i];
   do j = i+1 to dim(c);
      Var2 = c[j];
      Count = floor(10*uniform(1));
      output;
   end;
end;
keep Var1 Var2 Count;
run;

proc iml;
/* assume Have is sorted by (Var1, Var2) and that 
   all joint levels are represented (even zero counts) */
use Have;
read all var {Var1 Var2 Count};
close;

u = union(var1, var2); 
n = ncol(u);
M = j(n, n, 0);                   /* allocate matrix of zeros */
upperTriIdx = loc(row(M) &amp;lt; col(M)); /* upper triangular indices */
M[ upperTriIdx ] = Count; /* assign upper triangular values */
M = M + M`;               /* make symmeetric */
print M[r=u c=u];&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Dec 2017 10:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419551#M3890</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-12-09T10:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: convert 3 column dataset into matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419763#M3894</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;- A minor quibble.&amp;nbsp; Does not&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; loc&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;row&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;M&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt; col&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;M&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;generate indices for &lt;EM&gt;&lt;STRONG&gt;lower&lt;/STRONG&gt;&lt;/EM&gt; (rather than upper) triangle?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 03:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419763#M3894</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-12-09T03:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: convert 3 column dataset into matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419765#M3895</link>
      <description>&lt;P&gt;1. What I meant was ticker1 and ticker2 contains tickers from a set of tickers. If you are familiar with networks, this dataset is an edge list for a network and each observation specifies the weighted connection between 2 nodes (vertices).&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Sorry there should not be a position variable. I have removed it in the question. Regarding the second question, the Edge variable is used for the values of the matrix.&amp;nbsp; So its similar to correlation between 2 tickers in the correlation matrix.&lt;/P&gt;&lt;P&gt;I have updated the question.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 04:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419765#M3895</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2017-12-09T04:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: convert 3 column dataset into matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419790#M3898</link>
      <description>&lt;P&gt;Thanks, Mark. I have changed the inequality to match the comment.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 10:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419790#M3898</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-12-09T10:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: convert 3 column dataset into matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419791#M3899</link>
      <description>&lt;P&gt;Your example contains QQQ symbols, but your output does not contain those symbols. Please clarify.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2017 11:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419791#M3899</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-12-09T11:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: convert 3 column dataset into matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419983#M3904</link>
      <description>Sorry, I edited it.</description>
      <pubDate>Sun, 10 Dec 2017 22:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/convert-3-column-dataset-into-matrix/m-p/419983#M3904</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2017-12-10T22:48:02Z</dc:date>
    </item>
  </channel>
</rss>

