<?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 Re: Proc SQL: order by nulls last in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61170#M17363</link>
    <description>Check this will work.&lt;BR /&gt;
&lt;BR /&gt;
Proc sql;&lt;BR /&gt;
select col1,col2 from table&lt;BR /&gt;
order by (case when col1 is null then 999999 else col1 end) , col2;&lt;BR /&gt;
Quit;&lt;BR /&gt;
&lt;BR /&gt;
SD</description>
    <pubDate>Wed, 12 Jan 2011 16:39:47 GMT</pubDate>
    <dc:creator>sivaji</dc:creator>
    <dc:date>2011-01-12T16:39:47Z</dc:date>
    <item>
      <title>Proc SQL: order by nulls last</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61166#M17359</link>
      <description>Is it possible to order missing values at the end (SAS 9.1.3)?&lt;BR /&gt;
&lt;BR /&gt;
Some SQL-Standards support "order by nulls last". Is there a similar feature in Proc SQL or maybe in Proc Sort?&lt;BR /&gt;
&lt;BR /&gt;
Default Order (by year):&lt;BR /&gt;
.         407&lt;BR /&gt;
2008   123  &lt;BR /&gt;
2009   50&lt;BR /&gt;
2010   234&lt;BR /&gt;
&lt;BR /&gt;
Desired Order (by year nulls last)&lt;BR /&gt;
2008   123&lt;BR /&gt;
2009   50&lt;BR /&gt;
2010   234&lt;BR /&gt;
.         407</description>
      <pubDate>Tue, 11 Jan 2011 09:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61166#M17359</guid>
      <dc:creator>pichro</dc:creator>
      <dc:date>2011-01-11T09:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: order by nulls last</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61167#M17360</link>
      <description>hello,&lt;BR /&gt;
&lt;BR /&gt;
you can use proc format in combination with one data step and one proc sort:&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
input year amt;&lt;BR /&gt;
datalines;&lt;BR /&gt;
. 407&lt;BR /&gt;
2008 123 &lt;BR /&gt;
2009 50&lt;BR /&gt;
2010 234&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
      invalue change&lt;BR /&gt;
            .=9999&lt;BR /&gt;
            other=_same_;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data int;&lt;BR /&gt;
set test;&lt;BR /&gt;
s=input(put(year,best12.-l),change.);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=int out=test_sort(drop=s);&lt;BR /&gt;
by s;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Marius</description>
      <pubDate>Tue, 11 Jan 2011 11:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61167#M17360</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-11T11:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: order by nulls last</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61168#M17361</link>
      <description>Hello and thanks for the hint. It works well for the example, but i'm searching for a more general solution working for all datatypes and value ranges.</description>
      <pubDate>Tue, 11 Jan 2011 12:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61168#M17361</guid>
      <dc:creator>pichro</dc:creator>
      <dc:date>2011-01-11T12:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: order by nulls last</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61169#M17362</link>
      <description>I'd suggest selecting for the non-nulls and nulls separately and using a UNION with the nulls in the second part of the clause.</description>
      <pubDate>Tue, 11 Jan 2011 17:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61169#M17362</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2011-01-11T17:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: order by nulls last</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61170#M17363</link>
      <description>Check this will work.&lt;BR /&gt;
&lt;BR /&gt;
Proc sql;&lt;BR /&gt;
select col1,col2 from table&lt;BR /&gt;
order by (case when col1 is null then 999999 else col1 end) , col2;&lt;BR /&gt;
Quit;&lt;BR /&gt;
&lt;BR /&gt;
SD</description>
      <pubDate>Wed, 12 Jan 2011 16:39:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61170#M17363</guid>
      <dc:creator>sivaji</dc:creator>
      <dc:date>2011-01-12T16:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: order by nulls last</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61171#M17364</link>
      <description>The Problem is, that all solutions need information about the data. &lt;BR /&gt;
&lt;BR /&gt;
I'm searching for a general solution, which is not depending on data or datatype, and works for every dataset, like a standard SQL-Syntax or a SQL-Option. In Oracle-SQL there is a "order by nulls last", which does exactly the job i'm serching for. Is there something similar in SAS (Proc sort or Proc SQL)?</description>
      <pubDate>Thu, 13 Jan 2011 11:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61171#M17364</guid>
      <dc:creator>pichro</dc:creator>
      <dc:date>2011-01-13T11:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: order by nulls last</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61172#M17365</link>
      <description>...&lt;BR /&gt;
&amp;gt; In Oracle-SQL there is a "order by nulls last", which&lt;BR /&gt;
&amp;gt; does exactly the job i'm serching for. Is there&lt;BR /&gt;
&amp;gt; something similar in SAS (Proc sort or Proc SQL)?&lt;BR /&gt;
...&lt;BR /&gt;
No, there isn't.</description>
      <pubDate>Thu, 13 Jan 2011 15:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61172#M17365</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2011-01-13T15:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL: order by nulls last</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61173#M17366</link>
      <description>Thank You. At least i can stop searching for it.</description>
      <pubDate>Thu, 13 Jan 2011 15:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-order-by-nulls-last/m-p/61173#M17366</guid>
      <dc:creator>pichro</dc:creator>
      <dc:date>2011-01-13T15:49:08Z</dc:date>
    </item>
  </channel>
</rss>

