<?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 sort order of tables created with libname odbc in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/sort-order-of-tables-created-with-libname-odbc/m-p/511611#M73068</link>
    <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been recently testing the ability of creating tables on Microsoft SQL Server using libname odbc. I have been using the following approach:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
drop table sqllib.foo;
create table sqllib.foo as select * from saslib.foo;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Things have been working good so far. Unfortunately I have encountered some issues when trying to validate whether what was loaded into the DB is actually still the same data which is stored in sas datasets. Simple&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare data=sqllib.foo comp=saslib.foo&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;only works to a limited extent as&amp;nbsp;for the majority of the tables the order changes upon upload. I have been able to almost fix the issue by introducing an intermediate sort:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sqllib.foo out=foo_sql_sorted;
by a b;

proc sort data=saslib.foo out=foo_sas_sorted;
by a b;

proc compare data=foo_sas_sorted comp=foo_sql_sorted;
id a b;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unfortunately, the sort order is different for sql and sas data: sorted SAS dataset puts underscores after numbers:&lt;/P&gt;&lt;PRE&gt;a10_2
a11_2
a1_27&lt;/PRE&gt;&lt;P&gt;Whereas the sorted SQL data has underscores before numbers:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a1_27
a10_2
a11_2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried adding&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sortseq=ascii&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;to both proc sort statements but it did not help. The SQL server collation is set to Latin1_General_CI_AS. Is there a way to ensure that the sort order for both data sources is the same, or even better, to make sure that the order of the data does not change upon SQL table creation so that no sorting is required in the first place? Thank you for your support in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Nov 2018 08:35:11 GMT</pubDate>
    <dc:creator>js5</dc:creator>
    <dc:date>2018-11-09T08:35:11Z</dc:date>
    <item>
      <title>sort order of tables created with libname odbc</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-order-of-tables-created-with-libname-odbc/m-p/511611#M73068</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been recently testing the ability of creating tables on Microsoft SQL Server using libname odbc. I have been using the following approach:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
drop table sqllib.foo;
create table sqllib.foo as select * from saslib.foo;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Things have been working good so far. Unfortunately I have encountered some issues when trying to validate whether what was loaded into the DB is actually still the same data which is stored in sas datasets. Simple&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc compare data=sqllib.foo comp=saslib.foo&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;only works to a limited extent as&amp;nbsp;for the majority of the tables the order changes upon upload. I have been able to almost fix the issue by introducing an intermediate sort:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sqllib.foo out=foo_sql_sorted;
by a b;

proc sort data=saslib.foo out=foo_sas_sorted;
by a b;

proc compare data=foo_sas_sorted comp=foo_sql_sorted;
id a b;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Unfortunately, the sort order is different for sql and sas data: sorted SAS dataset puts underscores after numbers:&lt;/P&gt;&lt;PRE&gt;a10_2
a11_2
a1_27&lt;/PRE&gt;&lt;P&gt;Whereas the sorted SQL data has underscores before numbers:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a1_27
a10_2
a11_2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried adding&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sortseq=ascii&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;to both proc sort statements but it did not help. The SQL server collation is set to Latin1_General_CI_AS. Is there a way to ensure that the sort order for both data sources is the same, or even better, to make sure that the order of the data does not change upon SQL table creation so that no sorting is required in the first place? Thank you for your support in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 08:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-order-of-tables-created-with-libname-odbc/m-p/511611#M73068</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2018-11-09T08:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: sort order of tables created with libname odbc</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-order-of-tables-created-with-libname-odbc/m-p/511696#M73070</link>
      <description>Have you tried:&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;drop table sqllib.foo;&lt;BR /&gt;create table sqllib.foo as select * from saslib.foo order by a,b;</description>
      <pubDate>Fri, 09 Nov 2018 14:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-order-of-tables-created-with-libname-odbc/m-p/511696#M73070</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2018-11-09T14:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: sort order of tables created with libname odbc</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-order-of-tables-created-with-libname-odbc/m-p/511708#M73071</link>
      <description>&lt;P&gt;If you want&lt;/P&gt;
&lt;PRE&gt;a1_27
a10_2
a11_2&lt;/PRE&gt;
&lt;P&gt;sort order then try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sortseq=LINGUISTIC( Numeric_collation=on)&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 15:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-order-of-tables-created-with-libname-odbc/m-p/511708#M73071</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-09T15:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: sort order of tables created with libname odbc</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-order-of-tables-created-with-libname-odbc/m-p/511890#M73087</link>
      <description>&lt;P&gt;Try SORTPGM=SAS&amp;nbsp; when using PROC SORT on your ODBC library as explained here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=acreldb&amp;amp;docsetTarget=n10ap57wdc75v7n1vkej3wasjrvs.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=acreldb&amp;amp;docsetTarget=n10ap57wdc75v7n1vkej3wasjrvs.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to the same link SORTSEQ only works with SAS data, not DBMS data.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Nov 2018 01:05:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-order-of-tables-created-with-libname-odbc/m-p/511890#M73087</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-11-10T01:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: sort order of tables created with libname odbc</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-order-of-tables-created-with-libname-odbc/m-p/512111#M73089</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;! Adding&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options sortpgm=sas;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;has resolved the problem of the sort order being different. This is good enough to confirm that the data was not malformed by the DBMS upload.&lt;/P&gt;&lt;P&gt;Now I need to figure out why the order changes upon upload in the first place&amp;nbsp;and hopefully avoid the need for sorting altogether.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Nov 2018 08:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-order-of-tables-created-with-libname-odbc/m-p/512111#M73089</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2018-11-12T08:22:15Z</dc:date>
    </item>
  </channel>
</rss>

