<?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 Error when using order by in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314408#M68469</link>
    <description>&lt;P&gt;Your second example has SAS seeing the (...) as a subquery, which can't have ORDER BY. &amp;nbsp;Example 3 is just creating a new table using your criteria, which is perfectly acceptable (and something i do all the time).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For future reference and to speed up someone helping you, I recommend providing code using one of the SASHELP datasets (so the code can be replicated on anyone's SAS system), and also providng a copy / paste of the error message. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hoping this helps and good luck &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 26 Nov 2016 03:27:26 GMT</pubDate>
    <dc:creator>DarthPathos</dc:creator>
    <dc:date>2016-11-26T03:27:26Z</dc:date>
    <item>
      <title>Proc SQL Error when using order by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314390#M68463</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I encountered the error when I would like to use order by in Proc SQL. Below are three codes and their resuts.&lt;/P&gt;
&lt;P&gt;Why does code 2 generate error but code 3 works? Thanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Code 1:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table test2 as&lt;BR /&gt;(select *&lt;BR /&gt;from test);&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Resut: No Error&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Code 2:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table test2 as&lt;BR /&gt;(select *&lt;BR /&gt;from test&lt;/P&gt;
&lt;P&gt;order by 1,2);&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Resut: Error&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Code 3:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table test2 as&lt;BR /&gt;select *&lt;BR /&gt;from test&lt;/P&gt;
&lt;P&gt;order by 1,2;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Resut: No Error&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 01:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314390#M68463</guid>
      <dc:creator>MrBruce</dc:creator>
      <dc:date>2016-11-26T01:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Error when using order by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314403#M68466</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I did a google search, I got&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/order-by-in-subquery/td-p/15483" target="_self"&gt;this post&lt;/A&gt;&amp;nbsp;which answers your question. &amp;nbsp;Hope it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 03:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314403#M68466</guid>
      <dc:creator>DarthPathos</dc:creator>
      <dc:date>2016-11-26T03:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Error when using order by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314404#M68467</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the help. The link you provided explains that order by could be not be used in in-line view.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem that I encountered is that order by works fine when there are no parentheses, but generates an error when parentheses are used.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have any insights? Thanks. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bruce&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 03:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314404#M68467</guid>
      <dc:creator>MrBruce</dc:creator>
      <dc:date>2016-11-26T03:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Error when using order by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314408#M68469</link>
      <description>&lt;P&gt;Your second example has SAS seeing the (...) as a subquery, which can't have ORDER BY. &amp;nbsp;Example 3 is just creating a new table using your criteria, which is perfectly acceptable (and something i do all the time).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For future reference and to speed up someone helping you, I recommend providing code using one of the SASHELP datasets (so the code can be replicated on anyone's SAS system), and also providng a copy / paste of the error message. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hoping this helps and good luck &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 03:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314408#M68469</guid>
      <dc:creator>DarthPathos</dc:creator>
      <dc:date>2016-11-26T03:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Error when using order by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314412#M68471</link>
      <description>&lt;PRE&gt;
ORDER BY is to order the final result , therefore it should be used at the end of code.
Couldn't be used in Sub-Query .

&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Nov 2016 03:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314412#M68471</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-26T03:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Error when using order by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314422#M68474</link>
      <description>&lt;P&gt;You are getting an error in the second example because you included an ORDER BY clause in your sub-query. The first one does not generate an error since the sub-query doesn't have the ORDER BY clause. &amp;nbsp;As the third example shows you do not need to use a sub-query in a CREATE TABLE statement, so don't.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 05:25:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Error-when-using-order-by/m-p/314422#M68474</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-11-26T05:25:53Z</dc:date>
    </item>
  </channel>
</rss>

