BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
js5
Pyrite | Level 9 js5
Pyrite | Level 9

Dear community,

 

I have been recently testing the ability of creating tables on Microsoft SQL Server using libname odbc. I have been using the following approach:

 

proc sql;
drop table sqllib.foo;
create table sqllib.foo as select * from saslib.foo;

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

 

 

proc compare data=sqllib.foo comp=saslib.foo

only works to a limited extent as 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:

 

 

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;

Unfortunately, the sort order is different for sql and sas data: sorted SAS dataset puts underscores after numbers:

a10_2
a11_2
a1_27

Whereas the sorted SQL data has underscores before numbers:

a1_27
a10_2
a11_2

I tried adding 

sortseq=ascii

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Try SORTPGM=SAS  when using PROC SORT on your ODBC library as explained here:

https://documentation.sas.com/?docsetId=acreldb&docsetTarget=n10ap57wdc75v7n1vkej3wasjrvs.htm&docset...

 

According to the same link SORTSEQ only works with SAS data, not DBMS data.

View solution in original post

4 REPLIES 4
tomrvincent
Rhodochrosite | Level 12
Have you tried:

proc sql;
drop table sqllib.foo;
create table sqllib.foo as select * from saslib.foo order by a,b;
ballardw
Super User

If you want

a1_27
a10_2
a11_2

sort order then try

 

 

sortseq=LINGUISTIC( Numeric_collation=on)

SASKiwi
PROC Star

Try SORTPGM=SAS  when using PROC SORT on your ODBC library as explained here:

https://documentation.sas.com/?docsetId=acreldb&docsetTarget=n10ap57wdc75v7n1vkej3wasjrvs.htm&docset...

 

According to the same link SORTSEQ only works with SAS data, not DBMS data.

js5
Pyrite | Level 9 js5
Pyrite | Level 9

Thank you @SASKiwi! Adding

options sortpgm=sas;

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.

Now I need to figure out why the order changes upon upload in the first place and hopefully avoid the need for sorting altogether.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1111 views
  • 1 like
  • 4 in conversation