<?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-order matrix based on another index matrix. in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-order-matrix-based-on-another-index-matrix/m-p/34425#M167</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you can use the ideas in this blog post: &lt;A href="http://blogs.sas.com/content/iml/2011/03/16/sorting-a-matrix-by-row-or-column-statistics/"&gt;http://blogs.sas.com/content/iml/2011/03/16/sorting-a-matrix-by-row-or-column-statistics/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The post uses the SORTNDX function, which is explained further in this post: &lt;A href="http://blogs.sas.com/content/iml/2011/03/14/sorting-rows-of-a-matrix/"&gt;http://blogs.sas.com/content/iml/2011/03/14/sorting-rows-of-a-matrix/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your example, IDX is not a valid index into X because IDX contains the value 10. The expression x[10] does not make sense because X has fewer than 10 elements. If you define r=rank(idx), then zz=x[r,] is defined.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ranks and sorts can be confusing because &lt;A href="http://blogs.sas.com/content/iml/2011/04/06/how-to-rank-values/"&gt;sometimes you need to use the rank and sometimes you need to use the anti-rank&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Jan 2012 16:32:44 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2012-01-20T16:32:44Z</dc:date>
    <item>
      <title>Re-order matrix based on another index matrix.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-order-matrix-based-on-another-index-matrix/m-p/34424#M166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, there:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wonder how I should do it with SAS/IML. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Imagine x is a m*1 vector and I want to pick up some values from the specified positions defined by another vector, idx. For example, idx={ 2,3,7,5,10,2,7}.&amp;nbsp; I write a line as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;zz=x[idx,];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;zz is supposed to be a 7*1 vector whose values are from the values in corresponding positions in x, according to the index vector idx_k.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, the last line does not seem to be consistent with SAS/IML grammar. If we want to re-order a matrix based on an index defined by another matrix, how should we do it?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do find some example related to my question, but I find it difficult to interpret:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a sample code on how to use the rank function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;x={2 2 1 0 5};&amp;nbsp; /*value x&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;b=x;&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;&amp;nbsp; /*value b from x&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;x[,rank(x)]=b;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is difficult to understand the last line. does it revalue x? If so, can just write z[,rank(x)]=b, while z is undefined matrix or a 1*m matrix with m&amp;gt;=5 or can I write x[,rank(x)]=x?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jan 2012 16:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-order-matrix-based-on-another-index-matrix/m-p/34424#M166</guid>
      <dc:creator>bigbigben</dc:creator>
      <dc:date>2012-01-20T16:17:00Z</dc:date>
    </item>
    <item>
      <title>Re-order matrix based on another index matrix.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-order-matrix-based-on-another-index-matrix/m-p/34425#M167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you can use the ideas in this blog post: &lt;A href="http://blogs.sas.com/content/iml/2011/03/16/sorting-a-matrix-by-row-or-column-statistics/"&gt;http://blogs.sas.com/content/iml/2011/03/16/sorting-a-matrix-by-row-or-column-statistics/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The post uses the SORTNDX function, which is explained further in this post: &lt;A href="http://blogs.sas.com/content/iml/2011/03/14/sorting-rows-of-a-matrix/"&gt;http://blogs.sas.com/content/iml/2011/03/14/sorting-rows-of-a-matrix/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your example, IDX is not a valid index into X because IDX contains the value 10. The expression x[10] does not make sense because X has fewer than 10 elements. If you define r=rank(idx), then zz=x[r,] is defined.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ranks and sorts can be confusing because &lt;A href="http://blogs.sas.com/content/iml/2011/04/06/how-to-rank-values/"&gt;sometimes you need to use the rank and sometimes you need to use the anti-rank&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jan 2012 16:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-order-matrix-based-on-another-index-matrix/m-p/34425#M167</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2012-01-20T16:32:44Z</dc:date>
    </item>
  </channel>
</rss>

