<?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: Searching for values from a smaller set to fill in a vector in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/88260#M530</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think this question is answered.&amp;nbsp; Thank you for your help! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 29 May 2013 16:57:29 GMT</pubDate>
    <dc:creator>opti_miser</dc:creator>
    <dc:date>2013-05-29T16:57:29Z</dc:date>
    <item>
      <title>Searching for values from a smaller set to fill in a vector</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/88256#M526</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello.&amp;nbsp; I was wondering if there is a shortcut to achieving what I am trying to do, or if it is advisable to avoid the do loop. &lt;/P&gt;&lt;P&gt;I was thinking that the setdif or choose functions could help. &lt;/P&gt;&lt;P&gt;Thank you for any suggestions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;*one of two smaller sets;&lt;/P&gt;&lt;P&gt;one={1,3,6,8};&lt;/P&gt;&lt;P&gt;*union of two sets;&lt;/P&gt;&lt;P&gt;two={1,2,3,4,5,6,7,8};&lt;/P&gt;&lt;P&gt;*variable related to 'one';&lt;/P&gt;&lt;P&gt;three={0.1,0.2,0.3,0.4};&lt;/P&gt;&lt;P&gt;newmat=j(nrow(two),1,0);&lt;/P&gt;&lt;P&gt;do j=1 to nrow(two);&lt;/P&gt;&lt;P&gt;do k=1 to nrow(one);&lt;/P&gt;&lt;P&gt;*new set created with the same number of rows as set 'two'&lt;/P&gt;&lt;P&gt;containing either set three or filled in with zeros;&lt;/P&gt;&lt;P&gt;if two[j,]=one[k,] then newmat[j,]=three[k,];&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;print newmat;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 May 2013 22:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/88256#M526</guid>
      <dc:creator>opti_miser</dc:creator>
      <dc:date>2013-05-28T22:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for values from a smaller set to fill in a vector</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/88257#M527</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It looks like the logic is "If the j_th element of Two is in the set One, then use the elements in Three." Try using the ELEMENT function:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;newmat=j(nrow(Two),1,0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;idx = loc( element(Two, One) ); /* indices of elements in Two that match (make sure ncol(idx)&amp;gt;0) */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;v = Two[idx];&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* values of matching elements */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;do i = 1 to ncol(idx);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* for each value...&amp;nbsp; */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; n = idx&lt;I&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* location in NewMat to put answer*/&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; /* look up index in One. Use value from Three */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; newmat&lt;N&gt; = Three[ loc(One=v&lt;I&gt;) ];&lt;/I&gt;&lt;/N&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;print newmat;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For more on SAS/IML functions that operate on sets, see &lt;A class="active_link" href="http://blogs.sas.com/content/iml/2012/09/06/testing-for-equality-of-sets/" title="http://blogs.sas.com/content/iml/2012/09/06/testing-for-equality-of-sets/"&gt; Testing for equality of sets - The DO Loop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;And the LOC function is always your friend when you are looking up values: &lt;A href="http://blogs.sas.com/content/iml/2011/05/16/finding-data-that-satisfy-a-criterion/" title="http://blogs.sas.com/content/iml/2011/05/16/finding-data-that-satisfy-a-criterion/"&gt; Finding data that satisfy a criterion - The DO Loop&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2013 10:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/88257#M527</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2013-05-29T10:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for values from a smaller set to fill in a vector</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/88258#M528</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your help, Rick.&amp;nbsp; I need to get the union of two sets first.&amp;nbsp; So, my code structure actually looks like the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;*one of two smaller sets;&lt;/P&gt;&lt;P&gt;one={1,3,6,8};&lt;/P&gt;&lt;P&gt;*two of two smaller sets;&lt;/P&gt;&lt;P&gt;two={2,4,5,7};&lt;/P&gt;&lt;P&gt;*union of two sets;&lt;/P&gt;&lt;P&gt;uonetwo=t(union(one,two));&lt;/P&gt;&lt;P&gt;*weight from set one;&lt;/P&gt;&lt;P&gt;wone={0.1,0.2,0.3,0.4};&lt;/P&gt;&lt;P&gt;*weight from set two;&lt;/P&gt;&lt;P&gt;wtwo={0.5,0.6,0.7,0.8};&lt;/P&gt;&lt;P&gt;*new matrices of zeros from union set;&lt;/P&gt;&lt;P&gt;newmat1=j(nrow(uOneTwo),1,0);&lt;/P&gt;&lt;P&gt;newmat2=j(nrow(uOneTwo),1,0);&lt;/P&gt;&lt;P&gt;idx1 = loc( element(uOneTwo, One) );/* indices of elements in uOneTwo that match (make sure ncol(idx)&amp;gt;0) */&lt;/P&gt;&lt;P&gt;idx2 = loc( element(uOneTwo, Two) );/* indices of elements in uOneTwo that match (make sure ncol(idx)&amp;gt;0) */&lt;/P&gt;&lt;P&gt;v1 = uOneTwo[idx1];&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* values of matching elements */&lt;/P&gt;&lt;P&gt;v2 = uOneTwo[idx2];&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* values of matching elements */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i = 1 to ncol(idx1);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* for each value...&amp;nbsp; */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; n = idx1&lt;I&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* location in NewMat to put answer*/&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; /* look up index in One. Use value from Three */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; newmat1&lt;N&gt; = wOne[ loc(One=v1&lt;I&gt;) ];&lt;/I&gt;&lt;/N&gt;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i = 1 to ncol(idx2);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* for each value...&amp;nbsp; */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; n = idx2&lt;I&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* location in NewMat to put answer*/&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; /* look up index in One. Use value from Three */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; newmat2&lt;N&gt; = wTwo[ loc(Two=v2&lt;I&gt;) ];&lt;/I&gt;&lt;/N&gt;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;print NewMat1;&lt;/P&gt;&lt;P&gt;print NewMat2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2013 14:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/88258#M528</guid>
      <dc:creator>opti_miser</dc:creator>
      <dc:date>2013-05-29T14:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for values from a smaller set to fill in a vector</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/88259#M529</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I can't tell from your latest response: is this question answered or do you still have a question?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2013 16:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/88259#M529</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2013-05-29T16:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for values from a smaller set to fill in a vector</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/88260#M530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think this question is answered.&amp;nbsp; Thank you for your help! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2013 16:57:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/88260#M530</guid>
      <dc:creator>opti_miser</dc:creator>
      <dc:date>2013-05-29T16:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for values from a smaller set to fill in a vector</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/369829#M3544</link>
      <description>&lt;P&gt;Hi Rick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I came accross your answer since I am confronted with a similar issue. I can easily transscript this to alphanumerical as well as having column 2 of matrix two containing the values I like to know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;one = {a, c, e, h};&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;two = {a aa, b bb, c cc, d dd, e ee, f ff, g gg, h hh};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;idx = loc (element(two, one));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; v = two(idx);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i = 1 to ncol(idx);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; n = idx;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; newmat = two[loc(one=v),2];&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;print newmat;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, my real word looks different:&lt;/P&gt;&lt;P&gt;- 'one' contains strings, e.g.:&lt;/P&gt;&lt;P&gt;one = {hat, cap, bottle, bottleholder};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- 'two' contains even longer strings and multiple matches, e.g.:&lt;/P&gt;&lt;P&gt;two = {'mouse with glasses' '223 567', 'house with bottleholder in black' '345 987', 'baseballcap in blue' '678 912', 'pink baseballcap' 345 123', 'cap from plant material' '678 123' };&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I would like to find in 'two' all the "number strings" connected to the "word strings" which match the strings in 'one', including "baseballcap ..." such that the result would look something like&lt;/P&gt;&lt;P&gt;newmat_result = {'hat' '' '' '', 'cap' '678 912' '345 123' '678 123', bottle '' '' '', bottleholder '345 987' '' ''};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I worked with regular expressions before, but those were handwritten and not extracted from one matrix to match another matrix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After days of searching and trying, I hope that I find somebody with an idea to solve this issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any pointers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards from Germany&lt;/P&gt;&lt;P&gt;Gerit&lt;/P&gt;&lt;P&gt;PS: I made this reply into &lt;A href="https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Search-for-multiple-references-across-two-matrices/m-p/369860#M3545" target="_blank"&gt;a post&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 13:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Searching-for-values-from-a-smaller-set-to-fill-in-a-vector/m-p/369829#M3544</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2017-06-23T13:22:41Z</dc:date>
    </item>
  </channel>
</rss>

