<?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: Nested SQL joins in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Nested-SQL-joins/m-p/581690#M165352</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/85933"&gt;@Rohit_R&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ORDER BY clause must be at the end of the outermost query to be syntactically correct. (Note that t&lt;SPAN&gt;here's no need to sort anything else.)&amp;nbsp;&lt;/SPAN&gt;Due to the GROUP BY clause (with the same key variable) it should be redundant anyway, so you can simply delete it. Check section "Sort Information" of PROC CONTENTS output for table test1 to verify this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For further simplification I'd suggest to replace "&lt;FONT face="courier new,courier"&gt;select * from&lt;/FONT&gt; &lt;FONT face="courier new,courier"&gt;(&lt;/FONT&gt;&lt;EM&gt;innermost query&lt;/EM&gt;&lt;FONT face="courier new,courier"&gt;)&lt;/FONT&gt;" by "&lt;EM&gt;innermost query&lt;/EM&gt;".&lt;/P&gt;</description>
    <pubDate>Fri, 16 Aug 2019 11:43:45 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2019-08-16T11:43:45Z</dc:date>
    <item>
      <title>Nested SQL joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-SQL-joins/m-p/581666#M165342</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having some syntax trouble with this piece of code. It works fine when running in SQl but when running it using proc sql, it doesnt work except in the innermost select statement. I am not sure where the syntax error is :/.&lt;/P&gt;&lt;P&gt;The error is:&lt;/P&gt;&lt;P&gt;55 ) order by ORGN_ID)&lt;BR /&gt;_____ _&lt;BR /&gt;79 22&lt;BR /&gt;200&lt;BR /&gt;ERROR 79-322: Expecting a ).&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &amp;amp;, (, *, **, +, ',', -, '.', /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND,&lt;BR /&gt;ASC, ASCENDING, BETWEEN, CONTAINS, DESC, DESCENDING, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE,&lt;BR /&gt;NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code is:&lt;BR /&gt;proc sql;&lt;BR /&gt;create table test1 as&lt;BR /&gt;&lt;BR /&gt;select ORGN_ID, count(*) as V&lt;BR /&gt;from (&lt;BR /&gt;&amp;nbsp; &amp;nbsp; select ORGN_ID, ID_PERSON,count(distinct ID_PERSON)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; from (&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select *&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from (&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select AP.ORGN_ID,XX.ID_PERSON, count(AP.ORGN_ID) as VOL&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from PC.AP_SEC AP&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; left join PC.KEY_PERSON XX&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on AP.ID_APP=XX.ID_APP&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; left join PC.BUSINESS BS&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on AP.ID_BUSINESS=BS.ID_BUSINESS&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where BS.BSNSS_TYP = 'Z'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and (XX.SRNM is not null or XX.TTL is not null or XX.DT_OF_BRTH is not null )&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; group by AP.ORGN_ID,XX.ID_PERSON&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ) order by ORGN_ID&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ) group by ORGN_ID, ID_PERSON&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ) group by ORGN_ID;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2019 09:29:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-SQL-joins/m-p/581666#M165342</guid>
      <dc:creator>Rohit_R</dc:creator>
      <dc:date>2019-08-16T09:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: Nested SQL joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-SQL-joins/m-p/581690#M165352</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/85933"&gt;@Rohit_R&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ORDER BY clause must be at the end of the outermost query to be syntactically correct. (Note that t&lt;SPAN&gt;here's no need to sort anything else.)&amp;nbsp;&lt;/SPAN&gt;Due to the GROUP BY clause (with the same key variable) it should be redundant anyway, so you can simply delete it. Check section "Sort Information" of PROC CONTENTS output for table test1 to verify this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For further simplification I'd suggest to replace "&lt;FONT face="courier new,courier"&gt;select * from&lt;/FONT&gt; &lt;FONT face="courier new,courier"&gt;(&lt;/FONT&gt;&lt;EM&gt;innermost query&lt;/EM&gt;&lt;FONT face="courier new,courier"&gt;)&lt;/FONT&gt;" by "&lt;EM&gt;innermost query&lt;/EM&gt;".&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2019 11:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-SQL-joins/m-p/581690#M165352</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-08-16T11:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Nested SQL joins</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-SQL-joins/m-p/581697#M165357</link>
      <description>&lt;P&gt;Thank you FreelanceReinhard&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Removing the Order BY clause worked like a charm.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Rohit&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2019 12:07:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-SQL-joins/m-p/581697#M165357</guid>
      <dc:creator>Rohit_R</dc:creator>
      <dc:date>2019-08-16T12:07:31Z</dc:date>
    </item>
  </channel>
</rss>

