<?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: Select for data in table b based on table  a in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113123#M23343</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe something like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Create table final as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select b.*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from a left join b on a.id=b.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 18 Apr 2013 23:11:06 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2013-04-18T23:11:06Z</dc:date>
    <item>
      <title>Select for data in table b based on table  a</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113120#M23340</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I've a two tables.&lt;/P&gt;&lt;P&gt;I need email addresses for the IDs in table B that match table A.. However, the IDs in table B may be listed more than once because of different email addresses.&amp;nbsp; The IDs in Table A are listed only once.&amp;nbsp; And there're IDs in table B that I don't need as they've not listed in table A. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;Table A&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;BAC&lt;/P&gt;&lt;P&gt;IDG&lt;/P&gt;&lt;P&gt;IWL&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Table B&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; email&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BAC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:bacet@email.net"&gt;bacet@email.net&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BAC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:bacra@email.net"&gt;bacra@email.net&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IDG&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:edna@gmail.com"&gt;edna@gmail.com&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IWL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:larry@email.net"&gt;larry@email.net&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IWL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:edgar@email.net"&gt;edgar@email.net&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EEK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:lyons@eml.com"&gt;lyons@eml.com&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EEK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:reb@email.com"&gt;reb@email.com&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Final Table&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; email&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BAC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:bacet@email.net"&gt;bacet@email.net&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BAC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:bacra@email.net"&gt;bacra@email.net&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IDG&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:edna@gmail.com"&gt;edna@gmail.com&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IWL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:larry@email.net"&gt;larry@email.net&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IWL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;A href="mailto:edgar@email.net"&gt;edgar@email.net&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I only know how to do this if the IDs are listed once in Table B not more than once.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 22:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113120#M23340</guid>
      <dc:creator>jcis7</dc:creator>
      <dc:date>2013-04-18T22:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Select for data in table b based on table  a</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113121#M23341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi: this is very easy to do with the MERGE statement and the IN= option. I am not in a position to run SAS code right now, but if you look for examples of the MERGE statement, you should find the answer quickly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 22:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113121#M23341</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2013-04-18T22:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Select for data in table b based on table  a</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113122#M23342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are looking for how to solve many-to-many merges using sql, I just came across this paper yesterday that provides what I found to be an extremely nice way of explaining how to accomplish various merges using proc sql:&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/249-30.pdf" title="http://www2.sas.com/proceedings/sugi30/249-30.pdf"&gt;http://www2.sas.com/proceedings/sugi30/249-30.pdf&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 23:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113122#M23342</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-04-18T23:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Select for data in table b based on table  a</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113123#M23343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe something like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Create table final as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select b.*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from a left join b on a.id=b.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Apr 2013 23:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113123#M23343</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-04-18T23:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Select for data in table b based on table  a</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113124#M23344</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Perhaps your example is simpler than your actual data, but in your example the list of IDs Table A is unique.&amp;nbsp; So you do know how to do it.&amp;nbsp; Using normal SAS MERGE statement should work fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data FINAL;&lt;/P&gt;&lt;P&gt;merge A (in=in1) B (in=in2);&lt;/P&gt;&lt;P&gt;by id;&lt;/P&gt;&lt;P&gt;if in1 ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Apr 2013 04:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113124#M23344</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-04-19T04:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Select for data in table b based on table  a</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113125#M23345</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To do this in SAS datastep, both datasets will need to be sorted first on the common variable. The full code for doing the merge in datastep will turn out to be the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sort data=A;&lt;/P&gt;&lt;P&gt;by ID;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sort data=B;&lt;/P&gt;&lt;P&gt;by ID;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data FINAL;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;merge A (in=in1) B (in=in2);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;by id;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if in1 ;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So doing it in SQL is a lot easier option, the code for which is mentioned by &lt;STRONG style="font-size: 12px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;ballardw &lt;/STRONG&gt;above.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Apr 2013 11:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113125#M23345</guid>
      <dc:creator>JatinBansal</dc:creator>
      <dc:date>2013-04-19T11:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Select for data in table b based on table  a</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113126#M23346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OR SQL&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select * from b where b.id in ( select id from a ) ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Apr 2013 08:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113126#M23346</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-04-20T08:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Select for data in table b based on table  a</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113127#M23347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much Everyone!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 22:05:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113127#M23347</guid>
      <dc:creator>jcis7</dc:creator>
      <dc:date>2013-04-22T22:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: Select for data in table b based on table  a</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113128#M23348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is great - I tried it and it works well. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Question:&amp;nbsp; how do I check to see if the IDs in final table are the same as that in table a?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Apr 2013 18:15:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-for-data-in-table-b-based-on-table-a/m-p/113128#M23348</guid>
      <dc:creator>jcis7</dc:creator>
      <dc:date>2013-04-24T18:15:50Z</dc:date>
    </item>
  </channel>
</rss>

