<?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: Sort ascending with missing values in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26026#M5934</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I really like Howles' solution, it's elegant and simple, but in talking with a coworker he prefers not to use proc sql in his code. Ksharp's solution is good for him but was problematic as the sorting direction needed to change placing the nulls first. He had to change the temporary value in his code to correct this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The example was a dataset containing multiple sub-actions to a case_id. He was asked which sub-action is the most impacting for each case_id. To accomplish, he sorted the data on multiple columns with case_id as the first criteria. Then he sorted the data again with proc sort nodupkey by case_id to return the top record for each case_id. If his original sorting criteria is correct, he will return the most impacting sub-action for each case_id. However, when he needed to update the sorting direction of a column it placed weight on the nulls which caused the wrong case_id's to be returned.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Our solution was to expand on Ksharp's idea by adding columns using the missing() function. Then we could still use proc sort and not worry if he had to change the sort direction. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ismissingcol1 = missing(col1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ismissingcol2 = missing(col2);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data = test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by case_id ismissingcol1 col1 ismissingcol2 descending col2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort nodupkey data = test out = test_deduped (drop=ismissingcol1 ismissingcol2);&lt;/P&gt;&lt;P&gt;&amp;nbsp; by case_id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 Oct 2012 18:07:50 GMT</pubDate>
    <dc:creator>Matt_88</dc:creator>
    <dc:date>2012-10-24T18:07:50Z</dc:date>
    <item>
      <title>Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26014#M5922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to sort a list with missing values "." and the sort function places all the missing values at the beginning followed by ascending values.&amp;nbsp; Is there a way to sort and put the "." values at the end of the data?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Bo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Oct 2011 18:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26014#M5922</guid>
      <dc:creator>bolore</dc:creator>
      <dc:date>2011-10-07T18:33:35Z</dc:date>
    </item>
    <item>
      <title>Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26015#M5923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you don't mind the values being sorted in descending order you could use something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_ in (3,5,7) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(name);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by descending name;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Oct 2011 18:40:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26015#M5923</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-07T18:40:37Z</dc:date>
    </item>
    <item>
      <title>Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26016#M5924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could add another variable and include that in the sort.&lt;/P&gt;&lt;P&gt;If your sort variable is ID then you could create a 0/1 variable GROUP using this logic.&amp;nbsp; Then sort by group id and all of the missing values (group=1) will come after the non-missing values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; group = missing(id);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by group id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Oct 2011 19:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26016#M5924</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-07T19:16:05Z</dc:date>
    </item>
    <item>
      <title>Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26017#M5925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think there is also another way, namely creating a sortseq table with proc trantab and then using the sortseq option in proc sort. I don't have any experience with it, but possibly someone else can show us the way?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Oct 2011 19:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26017#M5925</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-07T19:20:43Z</dc:date>
    </item>
    <item>
      <title>Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26018#M5926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another workaround way is set missing value to a very large number, then set it back missing value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data temp;
a=2;output;
a=4;output;
a=.;output;
run;
proc stdize data=temp missing=999999 out=want reponly;run;
proc sort data=want;by a;run;
data want;set want; if a=999999 then a=.;run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Oct 2011 02:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26018#M5926</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-10-08T02:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26019#M5927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ... here are a couple other ideas&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;* some data with missing values;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;data class;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;set sashelp.class;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;name = ifc(ranuni(999) le .3, ' ', name);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;* sort non-missing;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;proc sort data=class (where=(^missing(name))) out=new;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;by name;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;* add missing at end; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;proc append base=new data=class(where=(missing(name)));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;* sort on a new variable within SQL, then drop it;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;create table new (drop=_x) as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;select *, 1 as _x from class (where=(^missing(name))) &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;union &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;select *, 2 as _x from class (where=(missing(name)))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;order by _x, name;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Oct 2011 23:39:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26019#M5927</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-10-08T23:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26020#M5928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I thin you are working too hard :-).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier New; color: #0000ff;"&gt;create&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;table&lt;SPAN style="color: #000000;"&gt; new &lt;/SPAN&gt;as&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier New; color: #0000ff;"&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;select&lt;SPAN style="color: #000000;"&gt; *&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier New;"&gt;&amp;nbsp; &lt;SPAN style="color: #0000ff;"&gt;from&lt;/SPAN&gt; class&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier New;"&gt; &lt;SPAN style="color: #0000ff;"&gt;order&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;by&lt;/SPAN&gt; missing(name) , name&lt;/P&gt;&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier New;"&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;P&gt;MikeZdeb wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi ... here are a couple other ideas&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;* some data with missing values;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;data class;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;set sashelp.class;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;name = ifc(ranuni(999) le .3, ' ', name);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;* sort non-missing;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;proc sort data=class (where=(^missing(name))) out=new;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;by name;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;* add missing at end; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;proc append base=new data=class(where=(missing(name)));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;* sort on a new variable within SQL, then drop it;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;create table new (drop=_x) as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;select *, 1 as _x from class (where=(^missing(name))) &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;union &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;select *, 2 as _x from class (where=(missing(name)))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;order by _x, name;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Oct 2011 02:09:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26020#M5928</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2011-10-09T02:09:09Z</dc:date>
    </item>
    <item>
      <title>Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26021#M5929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for all the helpful ideas. I used the work around KSharp suggested.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Oct 2011 10:48:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26021#M5929</guid>
      <dc:creator>bolore</dc:creator>
      <dc:date>2011-10-10T10:48:36Z</dc:date>
    </item>
    <item>
      <title>Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26022#M5930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just so it doesn't get lost, I think Howles suggestion was definitely the easiest to implement.&amp;nbsp; I.e.,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create&lt;SPAN style="font-size: 10px; color: #000000;"&gt; &lt;/SPAN&gt;table&lt;SPAN style="font-size: 10px; color: #000000;"&gt; new &lt;/SPAN&gt;as&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10px; color: #000000;"&gt; &lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&lt;SPAN style="font-size: 10px; color: #000000;"&gt; *&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10px; color: #0000ff;"&gt;from&lt;/SPAN&gt; sashelp.class&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10px; color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order&lt;/SPAN&gt; &lt;SPAN style="font-size: 10px; color: #0000ff;"&gt;by&lt;/SPAN&gt; missing(name) , name&lt;/P&gt;&lt;P&gt; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Oct 2011 13:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26022#M5930</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-10T13:10:03Z</dc:date>
    </item>
    <item>
      <title>Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26023#M5931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with Art totally. Howles is better than me.&lt;/P&gt;&lt;P&gt;I am happy that learning something new from him again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Oct 2011 01:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26023#M5931</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-10-11T01:39:23Z</dc:date>
    </item>
    <item>
      <title>Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26024#M5932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ksharp,&amp;nbsp; Just to be clear .. I was not picking on you.&amp;nbsp; You deserved to be credited with a correct answer and Howard is not better than you in all areas.&amp;nbsp; I was simply concerned that his suggested code might be overlooked when it was, in fact, a gem of a solution.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Oct 2011 02:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26024#M5932</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-11T02:47:46Z</dc:date>
    </item>
    <item>
      <title>Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26025#M5933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art. I understand what you mean.To be honest.&lt;/P&gt;&lt;P&gt;in this case, Howles 's way is better than me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Oct 2011 06:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26025#M5933</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-10-11T06:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Sort ascending with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26026#M5934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I really like Howles' solution, it's elegant and simple, but in talking with a coworker he prefers not to use proc sql in his code. Ksharp's solution is good for him but was problematic as the sorting direction needed to change placing the nulls first. He had to change the temporary value in his code to correct this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The example was a dataset containing multiple sub-actions to a case_id. He was asked which sub-action is the most impacting for each case_id. To accomplish, he sorted the data on multiple columns with case_id as the first criteria. Then he sorted the data again with proc sort nodupkey by case_id to return the top record for each case_id. If his original sorting criteria is correct, he will return the most impacting sub-action for each case_id. However, when he needed to update the sorting direction of a column it placed weight on the nulls which caused the wrong case_id's to be returned.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Our solution was to expand on Ksharp's idea by adding columns using the missing() function. Then we could still use proc sort and not worry if he had to change the sort direction. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ismissingcol1 = missing(col1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ismissingcol2 = missing(col2);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data = test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by case_id ismissingcol1 col1 ismissingcol2 descending col2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort nodupkey data = test out = test_deduped (drop=ismissingcol1 ismissingcol2);&lt;/P&gt;&lt;P&gt;&amp;nbsp; by case_id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Oct 2012 18:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Sort-ascending-with-missing-values/m-p/26026#M5934</guid>
      <dc:creator>Matt_88</dc:creator>
      <dc:date>2012-10-24T18:07:50Z</dc:date>
    </item>
  </channel>
</rss>

