<?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: Sql join to add variables to table A if there is a match in B in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/277993#M55897</link>
    <description>&lt;P&gt;Or there could be fewer than 500, if there are some clinics in data set A that don't exist in data set B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you say that the results were incorrect?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jun 2016 18:09:22 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-06-16T18:09:22Z</dc:date>
    <item>
      <title>Sql join to add variables to table A if there is a match in B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/277975#M55888</link>
      <description>&lt;P&gt;Hi!&amp;nbsp; Looking for some help with a sql join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table A has all the observations I need (500 obs) so the final table should have 500 obs regardless of Table B. (which has 300K obs)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table B has some additional variables I need only if the Parent_ID (Table B) match the DMID_ID in Table A.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried an inner join and left join but did not get correct output.&amp;nbsp; Help is appreciated!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc sql;&lt;BR /&gt;create table mtf.mtf_size as&lt;BR /&gt;SELECT a.*, b.parent_size, b.dmis_id, b.facility_type_code, b.facility_FIPS_country_code, b.dmis_parent_id, b.facility_service_code&lt;BR /&gt;from dmisid a inner join mtf.facility_size_all b &lt;BR /&gt;on a.dmid_id=b.parent_id; &lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 17:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/277975#M55888</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2016-06-16T17:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Sql join to add variables to table A if there is a match in B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/277986#M55893</link>
      <description>&lt;P&gt;Maybe you got the correct result and didn't know it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What would you expect to get if Table B contains 10 records for each PARENT_ID?&amp;nbsp; Wouldn't you then get 5,000 records as the final result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 17:57:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/277986#M55893</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-16T17:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sql join to add variables to table A if there is a match in B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/277989#M55894</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;Table B just contains a list of Clinics and their specific features.&amp;nbsp; Each observation is a unique clinic (e.g.Parent_id).&amp;nbsp; Now table A could have multiple ID's&amp;nbsp; that match a single clinic (parent_id) in Table B...so the variables for that ID match would populate&amp;nbsp; table A.&amp;nbsp; So the end table would always need to be 500 obs.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 18:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/277989#M55894</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2016-06-16T18:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sql join to add variables to table A if there is a match in B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/277993#M55897</link>
      <description>&lt;P&gt;Or there could be fewer than 500, if there are some clinics in data set A that don't exist in data set B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you say that the results were incorrect?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 18:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/277993#M55897</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-16T18:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Sql join to add variables to table A if there is a match in B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/277998#M55898</link>
      <description>&lt;P&gt;So, using my real numbers (rather than hypothetical) and my actual log...this is what I am seeing...The final table has far more observations than i want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;119&amp;nbsp; data dmisid;&lt;BR /&gt;120&amp;nbsp; set mtf;&lt;BR /&gt;121&amp;nbsp; parcost=coalescec (mtf, parcost);&lt;BR /&gt;122&amp;nbsp; run;&lt;BR /&gt;&lt;BR /&gt;NOTE: There were 436487 observations read from the data set WORK.MTF.&lt;BR /&gt;NOTE: The data set WORK.DMISID has 436487 observations and 102 variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;113&amp;nbsp; Proc sql;&lt;BR /&gt;114&amp;nbsp; create table mtf.mtf_size as&lt;BR /&gt;115&amp;nbsp; SELECT a.*, b.parent_size, b.dmis_id, b.facility_type_code, b.facility_name&lt;BR /&gt;116&amp;nbsp; from&amp;nbsp; dmisid a inner join mtf.facility_size_all b&lt;BR /&gt;117&amp;nbsp; on a.parcost=b.dmis_id;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;NOTE: Table MTF.MTF_SIZE created, with 3692241 rows and 106 columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;***Also note, Table B&amp;nbsp;mtf.facility_size_all has 5267 observations(the unique clinics).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 18:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/277998#M55898</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2016-06-16T18:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sql join to add variables to table A if there is a match in B</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/278007#M55900</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;I think I found my error!&amp;nbsp; I have duplicate clinics in&amp;nbsp; table B and I think that was dublicating observations in table A&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 18:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-join-to-add-variables-to-table-A-if-there-is-a-match-in-B/m-p/278007#M55900</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2016-06-16T18:49:38Z</dc:date>
    </item>
  </channel>
</rss>

