<?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 proc sql order of returned data in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-order-of-returned-data/m-p/350936#M63870</link>
    <description>&lt;P&gt;SAS discussion board&lt;/P&gt;
&lt;FORM id="aspnetForm" action="https://communities.sas.com/sites/pcd/orwiki/Lists/SAS%20discussion%20board/Flat.aspx?RootFolder=%2fsites%2fpcd%2forwiki%2fLists%2fSAS%20discussion%20board%2fPROC%20SQL%20question&amp;amp;FolderCTID=0x01200200D8E17B87F1590A4CAA25F5F878D37B9E&amp;amp;TopicsView=http%3A%2F%2Fwss%2Dfs%2Elink2%2Egpn%2Egov%2Euk%2Fsites%2Fpcd%2Forwiki%2FLists%2FSAS%2520discussion%2520board%2FAllItems%2Easpx" method="post" name="aspnetForm"&gt;
&lt;TABLE class="ms-main" width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;TABLE width="100%" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="ms-bodyareacell" valign="top"&gt;
&lt;TABLE id="MSO_ContentTable" class="ms-propertysheet" width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="ms-bodyareaframe" height="100%" valign="top"&gt;
&lt;TABLE width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD valign="top"&gt;
&lt;TABLE width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD valign="top"&gt;
&lt;DIV id="WebPartWPQ1"&gt;
&lt;TABLE width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;TABLE id="{1C2FC7CF-54A1-4AC1-9C8F-1914900BFA15}-{994D874A-F010-439B-99BF-C2E4B5F63134}" class="ms-disc" summary="SAS discussion board" width="100%" border="0" cellpadding="3" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="ms-disc-bordered-noleft" width="100%"&gt;
&lt;DIV class="ExternalClass635EF4DAE421450E8C85C77D38BE5B6A"&gt;
&lt;DIV&gt;Anyone have any idea how PROC SQL orders returned data for variables which have not been explicitly ordered or if there is a way of controlling it - for example with a many to many merge. Is there a rule about the order in which variables which are not explicitly part of the merge will be ? It does not seem to necessarily be the order in which they were in the source data. We are using SAS 9.3&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
With proc sort there is a system option (SORTEQUALS) which forces the order of the non sorted variables to be as in the source data but is there a similar control with proc sql ?&lt;/DIV&gt;
&lt;DIV class="ExternalClass635EF4DAE421450E8C85C77D38BE5B6A"&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Good practice will be to explicitly include the desired order in the proc sql but just wondering if there is a solution that does not require a change to code (other than perhaps an option). The problem has arisen as part of a move to SAS Enterprise Guide. Oddly exactly the same proc sql code returns observations in a different order (within by group) if submitted from a display manager interface compared to if submitted from Enterprise Guide. I can't reproduce with a simple dummy example. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/FORM&gt;</description>
    <pubDate>Tue, 18 Apr 2017 17:02:18 GMT</pubDate>
    <dc:creator>gaultie</dc:creator>
    <dc:date>2017-04-18T17:02:18Z</dc:date>
    <item>
      <title>proc sql order of returned data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-order-of-returned-data/m-p/350936#M63870</link>
      <description>&lt;P&gt;SAS discussion board&lt;/P&gt;
&lt;FORM id="aspnetForm" action="https://communities.sas.com/sites/pcd/orwiki/Lists/SAS%20discussion%20board/Flat.aspx?RootFolder=%2fsites%2fpcd%2forwiki%2fLists%2fSAS%20discussion%20board%2fPROC%20SQL%20question&amp;amp;FolderCTID=0x01200200D8E17B87F1590A4CAA25F5F878D37B9E&amp;amp;TopicsView=http%3A%2F%2Fwss%2Dfs%2Elink2%2Egpn%2Egov%2Euk%2Fsites%2Fpcd%2Forwiki%2FLists%2FSAS%2520discussion%2520board%2FAllItems%2Easpx" method="post" name="aspnetForm"&gt;
&lt;TABLE class="ms-main" width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;TABLE width="100%" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="ms-bodyareacell" valign="top"&gt;
&lt;TABLE id="MSO_ContentTable" class="ms-propertysheet" width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="ms-bodyareaframe" height="100%" valign="top"&gt;
&lt;TABLE width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD valign="top"&gt;
&lt;TABLE width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD valign="top"&gt;
&lt;DIV id="WebPartWPQ1"&gt;
&lt;TABLE width="100%" border="0" cellpadding="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;TABLE id="{1C2FC7CF-54A1-4AC1-9C8F-1914900BFA15}-{994D874A-F010-439B-99BF-C2E4B5F63134}" class="ms-disc" summary="SAS discussion board" width="100%" border="0" cellpadding="3" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="ms-disc-bordered-noleft" width="100%"&gt;
&lt;DIV class="ExternalClass635EF4DAE421450E8C85C77D38BE5B6A"&gt;
&lt;DIV&gt;Anyone have any idea how PROC SQL orders returned data for variables which have not been explicitly ordered or if there is a way of controlling it - for example with a many to many merge. Is there a rule about the order in which variables which are not explicitly part of the merge will be ? It does not seem to necessarily be the order in which they were in the source data. We are using SAS 9.3&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
With proc sort there is a system option (SORTEQUALS) which forces the order of the non sorted variables to be as in the source data but is there a similar control with proc sql ?&lt;/DIV&gt;
&lt;DIV class="ExternalClass635EF4DAE421450E8C85C77D38BE5B6A"&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Good practice will be to explicitly include the desired order in the proc sql but just wondering if there is a solution that does not require a change to code (other than perhaps an option). The problem has arisen as part of a move to SAS Enterprise Guide. Oddly exactly the same proc sql code returns observations in a different order (within by group) if submitted from a display manager interface compared to if submitted from Enterprise Guide. I can't reproduce with a simple dummy example. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/FORM&gt;</description>
      <pubDate>Tue, 18 Apr 2017 17:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-order-of-returned-data/m-p/350936#M63870</guid>
      <dc:creator>gaultie</dc:creator>
      <dc:date>2017-04-18T17:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql order of returned data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-order-of-returned-data/m-p/350940#M63871</link>
      <description>&lt;P&gt;SQL makes no guarantee on ordering. You might be seeing the results of running on multiple threads causing a change in the order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really do not have a set of keys then just order on everything. &amp;nbsp;You can use PROC SORT and the _ALL_ variable list. If you did have some partial keys that you want to order on add those in front of the _ALL_ keyword.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
  by key1 key2 _all_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Apr 2017 17:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-order-of-returned-data/m-p/350940#M63871</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-18T17:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql order of returned data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-order-of-returned-data/m-p/351219#M63897</link>
      <description>&lt;P&gt;If I can echo what Tom says SQL makes no guarantee of order. In fact the SQL language was designed for relational databases and when I was taught relational database theory (many decades ago) I was told that in an RDBMS order of records should never matter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're running your code against say ORACLE it's possible, as Tom says, that internally ORACLE is threading your query without you realising it.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2017 10:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-order-of-returned-data/m-p/351219#M63897</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-04-19T10:29:13Z</dc:date>
    </item>
  </channel>
</rss>

