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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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