<?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 Finding the location of matched values in two different vectors in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Finding-the-location-of-matched-values-in-two-different-vectors/m-p/45864#M275</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For example, here's one one approach:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u = unique(v);&lt;/P&gt;&lt;P&gt;free idx;&lt;/P&gt;&lt;P&gt;do i = 1 to ncol(u);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; k = loc(x=u&lt;I&gt;);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; idx = idx || k;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;print idx;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code isn't maximally efficient because it doesn't preallocate the IDX array (see &lt;A href="http://blogs.sas.com/content/iml/2011/06/20/pre-allocate-arrays-to-improve-efficiency/"&gt;http://blogs.sas.com/content/iml/2011/06/20/pre-allocate-arrays-to-improve-efficiency/&lt;/A&gt;). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Still it's not too bad. Use this if your vectors aren't too long. If this step is being used in the innermost loop of a long-running computation, write back. The code can be improved, but at the cost of additional complexitites.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 11 Nov 2011 11:51:45 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2011-11-11T11:51:45Z</dc:date>
    <item>
      <title>Finding the location of matched values in two different vectors</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Finding-the-location-of-matched-values-in-two-different-vectors/m-p/45862#M273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have been looking for a command in SAS/IML which finds the location of the matched values in two different vectors. &lt;/P&gt;&lt;P&gt;I came across this website: &lt;A href="http://stackoverflow.com/questions/4952548/value-matching-in-sas-iml"&gt;http://stackoverflow.com/questions/4952548/value-matching-in-sas-iml&lt;/A&gt; where the same question was asked and the suggested answer was to use XSECT function to find the intersection of the two sets. However, XSECT function gives the common elements between two sets rather that giving the location of those elements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, in the following code: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN style="color: navy; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;proc &lt;/SPAN&gt;&lt;SPAN style="color: navy; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;iml&lt;/SPAN&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;x={&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;10 &lt;/SPAN&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;11 &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;12 &lt;/SPAN&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;13 &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;12 &lt;/SPAN&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;13 &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;14 &lt;/SPAN&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;15&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;v={&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;12 &lt;/SPAN&gt;&lt;SPAN style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;13&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;z=xsect(x,v);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;print &lt;/SPAN&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;z;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the SAS result is: Z= {12&amp;nbsp;&amp;nbsp;&amp;nbsp; 13}, but I’mlooking for a vector like {3&amp;nbsp; 4&amp;nbsp; 5&amp;nbsp; 6} which is the location of common elements of vector V in vector X. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would anybody help me with the appropriate function inSAS/IML?&lt;/P&gt;&lt;P&gt;Thank you very much. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 23:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Finding-the-location-of-matched-values-in-two-different-vectors/m-p/45862#M273</guid>
      <dc:creator>Reza</dc:creator>
      <dc:date>2011-11-10T23:39:04Z</dc:date>
    </item>
    <item>
      <title>Finding the location of matched values in two different vectors</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Finding-the-location-of-matched-values-in-two-different-vectors/m-p/45863#M274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In SAS 9.3, the function you want is the &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/64248/HTML/default/viewer.htm#imlug_langref_sect083.htm"&gt;ELEMENT function&lt;/A&gt; teamed up with the LOC function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; idx=loc(element(x,v));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you haven't upgraded to SAS 9.3,&amp;nbsp; you can use the &lt;A href="http://blogs.sas.com/content/iml/2011/11/01/the-unique-loc-trick-a-real-treat/"&gt;UNIQUE-LOC technique&lt;/A&gt;, which I recently blogged about.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Nov 2011 01:39:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Finding-the-location-of-matched-values-in-two-different-vectors/m-p/45863#M274</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2011-11-11T01:39:34Z</dc:date>
    </item>
    <item>
      <title>Finding the location of matched values in two different vectors</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Finding-the-location-of-matched-values-in-two-different-vectors/m-p/45864#M275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For example, here's one one approach:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u = unique(v);&lt;/P&gt;&lt;P&gt;free idx;&lt;/P&gt;&lt;P&gt;do i = 1 to ncol(u);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; k = loc(x=u&lt;I&gt;);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; idx = idx || k;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;print idx;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code isn't maximally efficient because it doesn't preallocate the IDX array (see &lt;A href="http://blogs.sas.com/content/iml/2011/06/20/pre-allocate-arrays-to-improve-efficiency/"&gt;http://blogs.sas.com/content/iml/2011/06/20/pre-allocate-arrays-to-improve-efficiency/&lt;/A&gt;). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Still it's not too bad. Use this if your vectors aren't too long. If this step is being used in the innermost loop of a long-running computation, write back. The code can be improved, but at the cost of additional complexitites.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Nov 2011 11:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Finding-the-location-of-matched-values-in-two-different-vectors/m-p/45864#M275</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2011-11-11T11:51:45Z</dc:date>
    </item>
  </channel>
</rss>

