<?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 Sort question in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Proc-Sort-question/m-p/448475#M9906</link>
    <description>&lt;P&gt;PROC PRINT is just a method to display data.&lt;/P&gt;
&lt;P&gt;If you want to calculate sums then use PROC SUMMARY. With PROC SUMMARY you might be able to avoid the original sort and just use a CLASS statement instead of a BY statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway ;
class employee_id ;
var profit ;
output out=want sum= ;
run;
proc sort data=want ; by descending profit ; run;
proc print;
 var profit employee_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;(or possible roll your own by writing a query using PROC SQL).&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
  create table want as
      select employee_id,sum(profit) as profit 
      group by 1
      order by 2 desc
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also look at using PROC FREQ and trick it into make a sum by using your PROFIT variable as a WEIGHT variable.&amp;nbsp; But watch out if you have negative or zero values for profit.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have order=freq ;
  weight profit ;
  tables employee_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 25 Mar 2018 04:51:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-03-25T04:51:03Z</dc:date>
    <item>
      <title>Proc Sort question</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Proc-Sort-question/m-p/448454#M9902</link>
      <description>&lt;P&gt;I am new to SAS so my question might be simple but i can not find anything on the internet to answer it so that is why I am asking it. I have some data that I am doing a proc sort on. In the data the information is organized randomly so I am doing my initial sort on the employee_id. Then i am using a proc print to sum the profits of individual employees based on their id. to this extent now i need the profit to be sorted by the total of their sales so highest profit generator to the top and in a descending manner. Can you help?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 21:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Proc-Sort-question/m-p/448454#M9902</guid>
      <dc:creator>Dougfoley2</dc:creator>
      <dc:date>2018-03-24T21:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort question</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Proc-Sort-question/m-p/448456#M9903</link>
      <description>&lt;P&gt;Sounds like you have at least employee_id and some_profit_variable. Couldn't you just sort by:&lt;/P&gt;
&lt;PRE&gt;by employee_id descending some_profit_variable;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 21:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Proc-Sort-question/m-p/448456#M9903</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-03-24T21:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort question</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Proc-Sort-question/m-p/448462#M9904</link>
      <description>&lt;P&gt;The profit is based on transactions so the proc print is generating the sum for each employee. At this step is when i would need to restructure the data generated to make the total profit from the individual transactions in a descending manner.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 22:30:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Proc-Sort-question/m-p/448462#M9904</guid>
      <dc:creator>Dougfoley2</dc:creator>
      <dc:date>2018-03-24T22:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort question</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Proc-Sort-question/m-p/448466#M9905</link>
      <description>&lt;P&gt;Do you need to print each individual sale, or do you need to print just the total of all sales per employee_id?&lt;/P&gt;</description>
      <pubDate>Sat, 24 Mar 2018 23:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Proc-Sort-question/m-p/448466#M9905</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-24T23:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Sort question</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Proc-Sort-question/m-p/448475#M9906</link>
      <description>&lt;P&gt;PROC PRINT is just a method to display data.&lt;/P&gt;
&lt;P&gt;If you want to calculate sums then use PROC SUMMARY. With PROC SUMMARY you might be able to avoid the original sort and just use a CLASS statement instead of a BY statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway ;
class employee_id ;
var profit ;
output out=want sum= ;
run;
proc sort data=want ; by descending profit ; run;
proc print;
 var profit employee_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;(or possible roll your own by writing a query using PROC SQL).&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
  create table want as
      select employee_id,sum(profit) as profit 
      group by 1
      order by 2 desc
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also look at using PROC FREQ and trick it into make a sum by using your PROFIT variable as a WEIGHT variable.&amp;nbsp; But watch out if you have negative or zero values for profit.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have order=freq ;
  weight profit ;
  tables employee_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Mar 2018 04:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Proc-Sort-question/m-p/448475#M9906</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-25T04:51:03Z</dc:date>
    </item>
  </channel>
</rss>

