<?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 sum in descending order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610296#M177708</link>
    <description>&lt;P&gt;Thanks it works. However it gives me 2 rows with the 1st row represents sum of all profit irrespective of month.&lt;/P&gt;
&lt;P&gt;I accept the prior post as a solution and would appreciate if you could edit it further.&lt;/P&gt;</description>
    <pubDate>Sun, 08 Dec 2019 16:22:21 GMT</pubDate>
    <dc:creator>mrahouma</dc:creator>
    <dc:date>2019-12-08T16:22:21Z</dc:date>
    <item>
      <title>sort sum in descending order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610284#M177699</link>
      <description>&lt;P&gt;I have big database obtained from store data. I used the folowing code to identify which month has the highest profit&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=Superstore_Orders1; by order_month  descending profit ; run;
proc means data=Superstore_Orders1 sum ;
output out=sorted (drop= _TYPE_ _FREQ_); 
var   profit ; 
class  order_month ;  run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I got the following&amp;nbsp; in the results but I want to get the 2 months with highest profit in the output (I think through sorting sum in descending order). Any advice will be graetly appreciated&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 236px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34547iBD3A4210CA062C0F/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Dec 2019 14:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610284#M177699</guid>
      <dc:creator>mrahouma</dc:creator>
      <dc:date>2019-12-08T14:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: sort sum in descending order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610285#M177700</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SORT DATA = sorted ;
    BY DESCENDING sum;
RUN;

DATA want;
    SET sorted ;
    by DESCENDING sum;
    IF _n_&amp;lt;=2 THEN OUTPUT;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Dec 2019 15:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610285#M177700</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-12-08T15:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: sort sum in descending order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610288#M177702</link>
      <description>Thanks for your reply but sorry. This does not work. In log: " ERROR: Variable SUM not found."</description>
      <pubDate>Sun, 08 Dec 2019 15:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610288#M177702</guid>
      <dc:creator>mrahouma</dc:creator>
      <dc:date>2019-12-08T15:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: sort sum in descending order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610289#M177703</link>
      <description>ok could you please post the screenshot of the sorted dataset generated from proc means, I want to know the name of the sum variable</description>
      <pubDate>Sun, 08 Dec 2019 15:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610289#M177703</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-12-08T15:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: sort sum in descending order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610291#M177704</link>
      <description>&lt;P&gt;Here we are:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34548i3116AE6E62BCA2E1/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Dec 2019 15:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610291#M177704</guid>
      <dc:creator>mrahouma</dc:creator>
      <dc:date>2019-12-08T15:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: sort sum in descending order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610292#M177705</link>
      <description>&lt;P&gt;Please try below code , here I have subset only the SUM row and considered the first 2 highest sum&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SORT DATA = sorted ;
    BY DESCENDING profit;
where _stat_='SUM';
RUN;

DATA want;
    SET sorted ;
    by DESCENDING profit;
    IF _n_&amp;lt;=2 THEN OUTPUT;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Dec 2019 15:47:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610292#M177705</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-12-08T15:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: sort sum in descending order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610293#M177706</link>
      <description>in _STAT_, there is no "sum" and it gives me empty dataset upon running your code. Is there a way to fix my original code to get sum in the _STAT_ column so I can use your code&lt;BR /&gt;</description>
      <pubDate>Sun, 08 Dec 2019 15:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610293#M177706</guid>
      <dc:creator>mrahouma</dc:creator>
      <dc:date>2019-12-08T15:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: sort sum in descending order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610294#M177707</link>
      <description>&lt;P&gt;Sure please try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=Superstore_Orders1; 
by order_month  descending profit ;
 run;

proc means data=Superstore_Orders1 sum ;
output out=sorted (drop= _TYPE_ _FREQ_) sum=sum; 
var   profit ; 
class  order_month ;  
run;&lt;BR /&gt;&lt;BR /&gt;proc sort data=sorted ; 
by  descending sum;
 run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set sorted ;&lt;BR /&gt;by  descending sum;&lt;BR /&gt;if _n_&amp;lt;=2 then output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Dec 2019 15:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610294#M177707</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-12-08T15:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: sort sum in descending order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610296#M177708</link>
      <description>&lt;P&gt;Thanks it works. However it gives me 2 rows with the 1st row represents sum of all profit irrespective of month.&lt;/P&gt;
&lt;P&gt;I accept the prior post as a solution and would appreciate if you could edit it further.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Dec 2019 16:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610296#M177708</guid>
      <dc:creator>mrahouma</dc:creator>
      <dc:date>2019-12-08T16:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: sort sum in descending order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610297#M177709</link>
      <description>&lt;P&gt;Sure, please try below code, I included where order_month ne .;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=Superstore_Orders1; 
by order_month  descending profit ;
 run;

proc means data=Superstore_Orders1 sum ;
output out=sorted (drop= _TYPE_ _FREQ_) sum=sum; 
var   profit ; 
class  order_month ;  
run;

proc sort data=sorted ; 
by  descending sum;
where order_month ne .;
 run;


data want;
set sorted ;
by  descending sum;
if _n_&amp;lt;=2 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Dec 2019 16:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-sum-in-descending-order/m-p/610297#M177709</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-12-08T16:25:58Z</dc:date>
    </item>
  </channel>
</rss>

