<?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 Two queries in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Two-queries/m-p/260714#M50629</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought these two codes would return same results, however, the results were different with the duplicated records in the second query ( the original query data are all one patient having one record) . &amp;nbsp;&lt;/P&gt;&lt;P&gt;I am wondering the reason. &amp;nbsp;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table cohort as&lt;BR /&gt;select a.*&lt;BR /&gt;from lot2_2 as a&lt;BR /&gt;where a.patientid in&lt;BR /&gt;( select b.patientid&lt;BR /&gt;from &amp;amp;dblib..Lineoftherapy(where= (LineNumber = 1)) as b , &amp;amp;dblib..Demographics as c&lt;BR /&gt;where b.PatientID = c.PatientID and (year(b.StartDate) - c.BirthYear) &amp;gt;= 18 );&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table cohort as&lt;BR /&gt;select a.*&lt;BR /&gt;from lot2_2 as a , &amp;amp;dblib..Lineoftherapy(where= (LineNumber = 1)) as b , &amp;amp;dblib..Demographics as c&lt;BR /&gt;where ( a.patientid = b.PatientID = c.PatientID and (year(b.StartDate) - c.BirthYear) &amp;gt;= 18 );&lt;BR /&gt;quit;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Apr 2016 13:48:57 GMT</pubDate>
    <dc:creator>Ivy</dc:creator>
    <dc:date>2016-04-01T13:48:57Z</dc:date>
    <item>
      <title>Two queries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries/m-p/260714#M50629</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought these two codes would return same results, however, the results were different with the duplicated records in the second query ( the original query data are all one patient having one record) . &amp;nbsp;&lt;/P&gt;&lt;P&gt;I am wondering the reason. &amp;nbsp;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table cohort as&lt;BR /&gt;select a.*&lt;BR /&gt;from lot2_2 as a&lt;BR /&gt;where a.patientid in&lt;BR /&gt;( select b.patientid&lt;BR /&gt;from &amp;amp;dblib..Lineoftherapy(where= (LineNumber = 1)) as b , &amp;amp;dblib..Demographics as c&lt;BR /&gt;where b.PatientID = c.PatientID and (year(b.StartDate) - c.BirthYear) &amp;gt;= 18 );&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table cohort as&lt;BR /&gt;select a.*&lt;BR /&gt;from lot2_2 as a , &amp;amp;dblib..Lineoftherapy(where= (LineNumber = 1)) as b , &amp;amp;dblib..Demographics as c&lt;BR /&gt;where ( a.patientid = b.PatientID = c.PatientID and (year(b.StartDate) - c.BirthYear) &amp;gt;= 18 );&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 13:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries/m-p/260714#M50629</guid>
      <dc:creator>Ivy</dc:creator>
      <dc:date>2016-04-01T13:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries/m-p/260716#M50630</link>
      <description>&lt;P&gt;The first query is a subquery, and the result is Boolean&amp;nbsp;(true or false).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second is a join, the result is not restricted to true/false on the left table.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 13:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries/m-p/260716#M50630</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-04-01T13:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries/m-p/260791#M50652</link>
      <description>Thank you, LinusH !</description>
      <pubDate>Fri, 01 Apr 2016 17:20:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries/m-p/260791#M50652</guid>
      <dc:creator>Ivy</dc:creator>
      <dc:date>2016-04-01T17:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: Two queries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-queries/m-p/260803#M50653</link>
      <description>&lt;P&gt;The condition&amp;nbsp;&lt;EM&gt;a.patientid = b.PatientID = c.PatientID&lt;/EM&gt; isn't equivalent to &lt;EM&gt;(a.patientid = b.PatientID) and (b.PatientID = c.PatientID)&lt;/EM&gt;. It evaluates as &lt;EM&gt;(a.patientid = b.PatientID) = c.PatientID&lt;/EM&gt;. Now,&amp;nbsp;&lt;EM&gt;a.patientid = b.PatientID&lt;/EM&gt; elaluates as TRUE or FALSE (1 or 0) which is then compared to &lt;EM&gt;c.PatientID&lt;/EM&gt;. Unless &lt;EM&gt;c.PatientID&lt;/EM&gt; is 0 or 1, the condition will be FALSE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace&amp;nbsp;&lt;EM&gt;a.patientid = b.PatientID = c.PatientID&lt;/EM&gt;&amp;nbsp;with&amp;nbsp;&lt;EM&gt;(a.patientid = b.PatientID) and (b.PatientID = c.PatientID)&lt;/EM&gt; and both queries should yield the same result.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 18:32:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-queries/m-p/260803#M50653</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-04-01T18:32:52Z</dc:date>
    </item>
  </channel>
</rss>

