<?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: Different sort orders in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61586#M17489</link>
    <description>Thank you for your suggestions. &lt;BR /&gt;
&lt;BR /&gt;
I'm a bit confused.  This query is an implicit query.  It was my understanding the query was passed back to SAS for processing which even if teradata resided on a different platform, the SAS platform should control the order.  &lt;BR /&gt;
&lt;BR /&gt;
In my case however,  teradata and SAS are both ascii platforms, and the returned order from the teradata query does not match either sequence.  My records with mkt_seg_idfr = C148l are intermingled among the all upper case records.  They should be grouped either at begining or end if they were following collating sequence rules.  &lt;BR /&gt;
&lt;BR /&gt;
I'm looking at some other things right now concerning dbms sort stability which may explain this behavior.  I find myself asking the question why waste processing time with an order by statement, if you have to resort the data.&lt;BR /&gt;
&lt;BR /&gt;
Just thought someone else may have encountered this strange behavior. Thanks again for your help</description>
    <pubDate>Wed, 05 Aug 2009 16:16:18 GMT</pubDate>
    <dc:creator>LAP</dc:creator>
    <dc:date>2009-08-05T16:16:18Z</dc:date>
    <item>
      <title>Different sort orders</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61583#M17486</link>
      <description>Why would a sql query with an orderby statement produce a different sort order than using a proc sort and a by statement identical to the order by sql statement?&lt;BR /&gt;
&lt;BR /&gt;
I am using the following procedure to read 3 different teradata tables (same structure just different tables).&lt;BR /&gt;
&lt;BR /&gt;
    create View HISTORY_PART_&amp;amp;i._Vw  as&lt;BR /&gt;
	  select  PROF_SEGM_ID &lt;BR /&gt;
             ,MKT_SEGM_IDFR &lt;BR /&gt;
             ,CMDY_LINE_ID &lt;BR /&gt;
             ,BUS_GRP_ID &lt;BR /&gt;
             ,BUS_CATG_CODE &lt;BR /&gt;
             ,ORIG_PROF_REG &lt;BR /&gt;
             ,DEST_PROF_REG &lt;BR /&gt;
             ,MGRL_CAR_KIND &lt;BR /&gt;
             ,F990_RPTG_DT_YRMO as yrmo&lt;BR /&gt;
             ,sum(TOTL_NET_REV) as rev&lt;BR /&gt;
             ,sum(TOTL_CWT/20)as tons&lt;BR /&gt;
             ,sum(CAR_CNT) as units&lt;BR /&gt;
      from prodvp20.&amp;amp;TABLE_NAME&lt;BR /&gt;
      where f990_rptg_dt_yrmo Between &amp;amp;&amp;amp;Start_YRMO&amp;amp;i and &amp;amp;&amp;amp;END_YRMO&amp;amp;i&lt;BR /&gt;
      GROUP by  BUS_GRP_ID&lt;BR /&gt;
               ,CMDY_LINE_ID&lt;BR /&gt;
               ,PROF_SEGM_ID&lt;BR /&gt;
               ,MKT_SEGM_IDFR &lt;BR /&gt;
               ,BUS_CATG_CODE&lt;BR /&gt;
               ,ORIG_PROF_REG&lt;BR /&gt;
               ,DEST_PROF_REG&lt;BR /&gt;
               ,MGRL_CAR_KIND&lt;BR /&gt;
               ,F990_RPTG_DT_YRMO&lt;BR /&gt;
     ORDER by   PROF_SEGM_ID&lt;BR /&gt;
               ,BUS_GRP_ID&lt;BR /&gt;
               ,CMDY_LINE_ID         &lt;BR /&gt;
               ,MKT_SEGM_IDFR &lt;BR /&gt;
               ,ORIG_PROF_REG&lt;BR /&gt;
               ,DEST_PROF_REG&lt;BR /&gt;
               ,MGRL_CAR_KIND&lt;BR /&gt;
               ,BUS_CATG_CODE       &lt;BR /&gt;
               ,F990_RPTG_DT_YRMO;&lt;BR /&gt;
&lt;BR /&gt;
I then interleave the data sets with in a data step as follows&lt;BR /&gt;
&lt;BR /&gt;
Data all;&lt;BR /&gt;
  set HISTORY_PART_1_Vw &lt;BR /&gt;
        HISTORY_PART_2_Vw &lt;BR /&gt;
        HISTORY_PART_3_Vw ;&lt;BR /&gt;
  by PROF_SEGM_ID BUS_GRP_ID CMDY_LINE_ID MKT_SEGM_IDFR &lt;BR /&gt;
       ORIG_PROF_REG DEST_PROF_REG MGRL_CAR_KIND   &lt;BR /&gt;
       BUS_CATG_CODE ;&lt;BR /&gt;
&lt;BR /&gt;
ERROR: BY variables are not properly sorted on data set WORK.HISTORY_PART_2_VW.&lt;BR /&gt;
&lt;BR /&gt;
However, if I sort the results from the sql queries before I do the data step.  The order changes (from the sql query with order by statement) and the by statement in the data step does not produce an error.&lt;BR /&gt;
&lt;BR /&gt;
Adding a sort after the sql with an order by seems is inefficient especially since each of these data sets are quite large.&lt;BR /&gt;
 &lt;BR /&gt;
I should add that the sql statement (with order by) has been in production for the past 18months with no problems, but the data today had some bad observations where MKT_SEGM_IDFR = C148l and C148L and the order in the order by was different than the order when I sorted the query so the interleave step failed.&lt;BR /&gt;
&lt;BR /&gt;
Any thoughts?  Is there something that I am missing here.&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Tue, 04 Aug 2009 23:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61583#M17486</guid>
      <dc:creator>LAP</dc:creator>
      <dc:date>2009-08-04T23:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Different sort orders</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61584#M17487</link>
      <description>Different hardware platforms have different sort orders (called collating sequences).  Your SQL query is being passed to the teradata server (perhaps an IBM mainframe) for sorting and a PROC SORT is being executed on your SAS Server (more likely a Unix or PC platform).&lt;BR /&gt;
&lt;BR /&gt;
Doc Muhlbaier&lt;BR /&gt;
Duke</description>
      <pubDate>Wed, 05 Aug 2009 03:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61584#M17487</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2009-08-05T03:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Different sort orders</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61585#M17488</link>
      <description>True.&lt;BR /&gt;
I've faced this issue sometime with data coming from a z/OS platform to Unix.&lt;BR /&gt;
&lt;BR /&gt;
Luckily, PROC SORT procedure provides the SORTSEQ option to enable you to specify the collating sequence for your sort. You can even build up your own translation table that suits your needs through the PROC TRANTAB procedure.&lt;BR /&gt;
&lt;BR /&gt;
See the SORTSEQ option:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/hostwin/61924/HTML/default/chsortfstart.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/hostwin/61924/HTML/default/chsortfstart.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
And the TRANTAB procedure;&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/nlsref/61893/HTML/default/a000146227.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/nlsref/61893/HTML/default/a000146227.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Wed, 05 Aug 2009 10:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61585#M17488</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-08-05T10:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Different sort orders</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61586#M17489</link>
      <description>Thank you for your suggestions. &lt;BR /&gt;
&lt;BR /&gt;
I'm a bit confused.  This query is an implicit query.  It was my understanding the query was passed back to SAS for processing which even if teradata resided on a different platform, the SAS platform should control the order.  &lt;BR /&gt;
&lt;BR /&gt;
In my case however,  teradata and SAS are both ascii platforms, and the returned order from the teradata query does not match either sequence.  My records with mkt_seg_idfr = C148l are intermingled among the all upper case records.  They should be grouped either at begining or end if they were following collating sequence rules.  &lt;BR /&gt;
&lt;BR /&gt;
I'm looking at some other things right now concerning dbms sort stability which may explain this behavior.  I find myself asking the question why waste processing time with an order by statement, if you have to resort the data.&lt;BR /&gt;
&lt;BR /&gt;
Just thought someone else may have encountered this strange behavior. Thanks again for your help</description>
      <pubDate>Wed, 05 Aug 2009 16:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61586#M17489</guid>
      <dc:creator>LAP</dc:creator>
      <dc:date>2009-08-05T16:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Different sort orders</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61587#M17490</link>
      <description>Hi There; could you log this one into SAS technical support.  i'm suspecting the default sort ordering on the teradata side is "case indifferent", which causes the SAS BY logic that checks for by groups variables being in "ever increasing" order...  there is probably some SAS or teradata option to request lowercase before uppercase, and the pros in tech support can help us find it/&lt;BR /&gt;
&lt;BR /&gt;
paul</description>
      <pubDate>Thu, 06 Aug 2009 02:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61587#M17490</guid>
      <dc:creator>Paul_Kent_SAS</dc:creator>
      <dc:date>2009-08-06T02:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: Different sort orders</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61588#M17491</link>
      <description>Definitely consideration for OS platform (ASCII or EBCDIC) affecting collation sequence, as well as Teradata specific behavior, which I found in the document below:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://www.teradataforum.com/teradata_pdf/b035-1101-061a_1.pdf" target="_blank"&gt;http://www.teradataforum.com/teradata_pdf/b035-1101-061a_1.pdf&lt;/A&gt; - section on topic "About Collation Sequences".&lt;BR /&gt;
&lt;BR /&gt;
References on SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website also mention that you consider specifying the ORDER BY outside the parenthese so the event occurs post-RDBMS extract processing.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 06 Aug 2009 03:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Different-sort-orders/m-p/61588#M17491</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-08-06T03:09:34Z</dc:date>
    </item>
  </channel>
</rss>

