<?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: Match merging using a secondary match variable. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Match-merging-using-a-secondary-match-variable/m-p/565700#M158863</link>
    <description>&lt;P&gt;An elegant, relatively fast approach would use two hash tables.&amp;nbsp; In one DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create a hash table from B that uses TICKER as the key and OTHER_STUFF as the data.&lt;/LI&gt;
&lt;LI&gt;Create another hash table from B that uses SECOND_TICKER as the key and OTHER_STUFF as the data.&lt;/LI&gt;
&lt;LI&gt;Read in an observation from data set A, and compare to the hash tables.&amp;nbsp; More specifically, see if there's a match in hash table #1.&amp;nbsp; If so, read in OTHER_STUFF.&amp;nbsp; If not, see if there is a match in hash table #2.&amp;nbsp; If so, read in OTHER_STUFF.&lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Wed, 12 Jun 2019 22:09:26 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-06-12T22:09:26Z</dc:date>
    <item>
      <title>Match merging using a secondary match variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-merging-using-a-secondary-match-variable/m-p/565679#M158853</link>
      <description>&lt;P&gt;Desire to match merge two data sets.&amp;nbsp; The wrinkle is that&amp;nbsp; If there is no match using a primary match variable, I'd like to also try to match with a secondary match variable.&amp;nbsp; There is probably a simple way to do this but I haven't found it.&amp;nbsp; Here's an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data A;&lt;/P&gt;&lt;P&gt;TICKER&amp;nbsp; &amp;nbsp; Price&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11&lt;/P&gt;&lt;P&gt;S&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data B;&lt;/P&gt;&lt;P&gt;TICKER&amp;nbsp; SECOND_TICKER&amp;nbsp; OTHER_STUFF;&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Consumer&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZZ&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; REIT&lt;/P&gt;&lt;P&gt;KMT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; S&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Consumer&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BMT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Industrial&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&amp;nbsp; A match merge of A and B using ticker, but if no match on ticker, then try finding one by using "second_ticker" as the match variable.&amp;nbsp; This would be the ideal output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data C:&lt;/P&gt;&lt;P&gt;TICKER&amp;nbsp; &amp;nbsp;SECOND_TICKER&amp;nbsp; PRICE&amp;nbsp; OTHER_STUFF&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Consumer&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;zz&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; REIT&lt;/P&gt;&lt;P&gt;S&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; S&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Consumer&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BMT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Industrial&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, there is no match between datasets A and B&amp;nbsp;&amp;nbsp;for the observation with ticker=S when using ticker as the primary match variable.&amp;nbsp; &amp;nbsp;However, there is a match for the no-match observation (ticker= S) between datasets A and B if we try again searching for matches using second_ticker in Dataset B and ticker in A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can accomplish this in a messy way by defining temporary match variables and doing multiple passes through the data&amp;nbsp; - eventually combining partial results.&amp;nbsp; But, Is there an elegant solution, or am I missing something obvious (SAS v9.4)?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 20:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-merging-using-a-secondary-match-variable/m-p/565679#M158853</guid>
      <dc:creator>mauimaggie</dc:creator>
      <dc:date>2019-06-12T20:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Match merging using a secondary match variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-merging-using-a-secondary-match-variable/m-p/565683#M158855</link>
      <description>Do both the joins using SQL and use COALESCE() to take the one that matches. &lt;BR /&gt;&lt;BR /&gt;Untested, but something like this:&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as &lt;BR /&gt;select a.*, coalesce(t2.other_stuff, t3.other_stuff) as other_stuff&lt;BR /&gt;from have as a&lt;BR /&gt;left join secondTable as t2&lt;BR /&gt;on a.ticker=t2.ticker&lt;BR /&gt;left join secondTable as t3&lt;BR /&gt;on a.secondTicker=t3.ticker;&lt;BR /&gt;quit;</description>
      <pubDate>Wed, 12 Jun 2019 20:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-merging-using-a-secondary-match-variable/m-p/565683#M158855</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-12T20:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Match merging using a secondary match variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-merging-using-a-secondary-match-variable/m-p/565700#M158863</link>
      <description>&lt;P&gt;An elegant, relatively fast approach would use two hash tables.&amp;nbsp; In one DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create a hash table from B that uses TICKER as the key and OTHER_STUFF as the data.&lt;/LI&gt;
&lt;LI&gt;Create another hash table from B that uses SECOND_TICKER as the key and OTHER_STUFF as the data.&lt;/LI&gt;
&lt;LI&gt;Read in an observation from data set A, and compare to the hash tables.&amp;nbsp; More specifically, see if there's a match in hash table #1.&amp;nbsp; If so, read in OTHER_STUFF.&amp;nbsp; If not, see if there is a match in hash table #2.&amp;nbsp; If so, read in OTHER_STUFF.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 12 Jun 2019 22:09:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-merging-using-a-secondary-match-variable/m-p/565700#M158863</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-06-12T22:09:26Z</dc:date>
    </item>
  </channel>
</rss>

