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!
Try SORTPGM=SAS when using PROC SORT on your ODBC library as explained here:
According to the same link SORTSEQ only works with SAS data, not DBMS data.
If you want
a1_27 a10_2 a11_2
sort order then try
sortseq=LINGUISTIC( Numeric_collation=on)
Try SORTPGM=SAS when using PROC SORT on your ODBC library as explained here:
According to the same link SORTSEQ only works with SAS data, not DBMS data.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.