<?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: Proc SQL output file has missing ID variables but input files do not in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-output-file-has-missing-ID-variables-but-input-files-do/m-p/235232#M55032</link>
    <description>&lt;P&gt;Which MISS_ID variables are you talking about:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; &amp;nbsp;as Select a.MSIS_ID, a.DX, b.MSIS_ID, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I will assume it is A.MSIS_ID. &amp;nbsp;The reason is your right joining the A dataset onto the B dataset, all records from B will be present, even if there is no match in A. &amp;nbsp;Consider:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If I right join A to B, 2-2, 3-3, -1, so B's id is present, but A has no match and so becomes missing. &amp;nbsp;What you should do is either use B.MSIS_ID as that will always be present. &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/869i2A88846B65136861/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Nov 2015 14:06:50 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-11-18T14:06:50Z</dc:date>
    <item>
      <title>Proc SQL output file has missing ID variables but input files do not</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-output-file-has-missing-ID-variables-but-input-files-do/m-p/235221#M55029</link>
      <description>&lt;P&gt;I'm combining 2 files by an ID variable.&amp;nbsp; Each of the input files has approximately 5000 records, and none of them have missing data for the ID variable.&amp;nbsp; The output file has about 7400 records, about 800 of which have missing data for the ID variable.&amp;nbsp; How can that be?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc SQL;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Create Table &amp;amp;state..&amp;amp;state.&amp;amp;year._IMG8_matched_DX_IMAGED &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;as Select a.MSIS_ID, a.DX, b.MSIS_ID, b.IMGPROC, a.SRVC_BGN_DT, b.SRVC_BGN_DT,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;a.SRVC_BGN_DT as DxDatenum, &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;b.SRVC_BGN_DT as IMGDatenum&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;from&amp;nbsp; &amp;amp;state..ipot&amp;amp;year._&amp;amp;state._IMGmeas8_DX as a&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;RIGHT JOIN &amp;amp;state..ipot&amp;amp;year._&amp;amp;state._IMGmeas8_IMAGED as b&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ON a.MSIS_ID = b.MSIS_ID;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2015 13:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-output-file-has-missing-ID-variables-but-input-files-do/m-p/235221#M55029</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2015-11-18T13:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL output file has missing ID variables but input files do not</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-output-file-has-missing-ID-variables-but-input-files-do/m-p/235228#M55030</link>
      <description>You are using a right join so the missing 800 have a record in &amp;amp;state..ipot&amp;amp;year._&amp;amp;state._IMGmeas8_IMAGED but do not in &amp;amp;state..ipot&amp;amp;year._&amp;amp;state._IMGmeas8_DX&lt;BR /&gt;&lt;BR /&gt;Therefore because its SQL and a right join its keeping all of the records from the right table and only joining the variables from the left which have a MSIS_ID which is in both tables. Also you should rename MSIS_ID from one of the two tables, right now you are asking it to pull in MSIS_ID from both tables and place them in the new dataset, however you cannot have 2 variables with the same name, so to make sure that you are pulling in everything that you want have the two variables names something different, ie &lt;BR /&gt;a.MSIS_ID, (b.MSIS_ID) as MSIS_ID2 ...&lt;BR /&gt;This also explains why you have missing ID variables because since its a right join MSIS_ID is being brought in after a missing value from the left table, but SQL isn't overwriting it, so it shows up as missing.&lt;BR /&gt;&lt;BR /&gt;So the moral of the story is change the variable name for one of the two MSIS_ID variables and the ID variables will be available from both tables again.&lt;BR /&gt;&lt;BR /&gt;Hope this helps.</description>
      <pubDate>Wed, 18 Nov 2015 14:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-output-file-has-missing-ID-variables-but-input-files-do/m-p/235228#M55030</guid>
      <dc:creator>overmar</dc:creator>
      <dc:date>2015-11-18T14:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL output file has missing ID variables but input files do not</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-output-file-has-missing-ID-variables-but-input-files-do/m-p/235232#M55032</link>
      <description>&lt;P&gt;Which MISS_ID variables are you talking about:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; &amp;nbsp;as Select a.MSIS_ID, a.DX, b.MSIS_ID, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I will assume it is A.MSIS_ID. &amp;nbsp;The reason is your right joining the A dataset onto the B dataset, all records from B will be present, even if there is no match in A. &amp;nbsp;Consider:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If I right join A to B, 2-2, 3-3, -1, so B's id is present, but A has no match and so becomes missing. &amp;nbsp;What you should do is either use B.MSIS_ID as that will always be present. &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/869i2A88846B65136861/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2015 14:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-output-file-has-missing-ID-variables-but-input-files-do/m-p/235232#M55032</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-11-18T14:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL output file has missing ID variables but input files do not</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-output-file-has-missing-ID-variables-but-input-files-do/m-p/235314#M55047</link>
      <description>Check your log for a warning. That should tell you something's wrong. &lt;BR /&gt;&lt;BR /&gt;Your code doesn't make a lot of sense as you select variables multiple times, but don't rename them, how would you know which dataset they come from?&lt;BR /&gt;&lt;BR /&gt;You can look into the coalesce function, which may help.</description>
      <pubDate>Wed, 18 Nov 2015 17:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-output-file-has-missing-ID-variables-but-input-files-do/m-p/235314#M55047</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-18T17:23:19Z</dc:date>
    </item>
  </channel>
</rss>

