BookmarkSubscribeRSS Feed
Scottcom4
Calcite | Level 5
Hi All,

I am trying to sort using SQL (as I am reading the data in from an oracle database and this appears to be the most efficient method), however it sorts blanks last. As a result I get:

1
2
.
.
.


Where as with Proc Sort I get:

.
.
.
1
2

Does anyone know a way to have Proc SQL sort in the same way that Proc Sort does?

Thank you for your help.
3 REPLIES 3
deleted_user
Not applicable
Hi,

Please try this

data x;
input a;
cards;
1
2
.
.
.
;
run;

proc sql;
create table x1 as
select *
from x
order by a;
quit;

Rgds,
skm
DanielSantos
Barite | Level 11
Trouble is MISSING/NULLS have different meanings for ORACLE and SAS.

When you perform an Order by through SQL Pass-Through (on the ORACLE side), it seems NULLS are considered a very big number.
When you perform a SAS SORT, MISSINGS are considered a very little number.

Have you tried to order through a COALESCE function?

ORDER BY COALESCE (COL, -1)

The COALESCE function causes any results that are NULL to be replaced by some other value you wish (in the example, -1).

Not a pretty solution, but a easy one that may do what you whish.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Scottcom4
Calcite | Level 5
Thank you so much Daniel. Your explanation was very clear and everything worked perfectly.

Greatly appreciated.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 646 views
  • 0 likes
  • 3 in conversation