<?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 How to Sort Data from Highest to Lowest and Print Top Ten Highest Salaries in Programming 1 and 2</title>
    <link>https://communities.sas.com/t5/Programming-1-and-2/How-to-Sort-Data-from-Highest-to-Lowest-and-Print-Top-Ten/m-p/715166#M691</link>
    <description>&lt;P&gt;Hi I am working on a problem where I imported an Excel file to SAS&lt;/P&gt;&lt;P&gt;and I need to Sort Salaries of Baseball players and print the top ten largest salaries.&lt;/P&gt;&lt;P&gt;I tried to sort it but it is only sorting the first ten from my dataset from greatest to smallest and it is not getting the top ten greatest salaries from the entire dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=MLB out=salaries_sorted;
	format Salary dollar12.3;
	by descending Salary descending Year;
	proc print data=MLB (obs=10);
	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The results I have right now and the expected results are in pdfs and I have the excel file included too.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jan 2021 04:01:51 GMT</pubDate>
    <dc:creator>Anonymous6</dc:creator>
    <dc:date>2021-01-29T04:01:51Z</dc:date>
    <item>
      <title>How to Sort Data from Highest to Lowest and Print Top Ten Highest Salaries</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/How-to-Sort-Data-from-Highest-to-Lowest-and-Print-Top-Ten/m-p/715166#M691</link>
      <description>&lt;P&gt;Hi I am working on a problem where I imported an Excel file to SAS&lt;/P&gt;&lt;P&gt;and I need to Sort Salaries of Baseball players and print the top ten largest salaries.&lt;/P&gt;&lt;P&gt;I tried to sort it but it is only sorting the first ten from my dataset from greatest to smallest and it is not getting the top ten greatest salaries from the entire dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=MLB out=salaries_sorted;
	format Salary dollar12.3;
	by descending Salary descending Year;
	proc print data=MLB (obs=10);
	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The results I have right now and the expected results are in pdfs and I have the excel file included too.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 04:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/How-to-Sort-Data-from-Highest-to-Lowest-and-Print-Top-Ten/m-p/715166#M691</guid>
      <dc:creator>Anonymous6</dc:creator>
      <dc:date>2021-01-29T04:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sort Data from Highest to Lowest and Print Top Ten Highest Salaries</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/How-to-Sort-Data-from-Highest-to-Lowest-and-Print-Top-Ten/m-p/715169#M692</link>
      <description>&lt;P&gt;Your code is printing the first 10 observations of the original dataset, not the sorted version.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=MLB out=salaries_sorted;
  by descending Salary descending Year;
run;

proc print data=salaries_sorted(obs=10);
  format Salary dollar12.3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jan 2021 04:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/How-to-Sort-Data-from-Highest-to-Lowest-and-Print-Top-Ten/m-p/715169#M692</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-29T04:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sort Data from Highest to Lowest and Print Top Ten Highest Salaries</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/How-to-Sort-Data-from-Highest-to-Lowest-and-Print-Top-Ten/m-p/715170#M693</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; How do I print the sorted dataset?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 04:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/How-to-Sort-Data-from-Highest-to-Lowest-and-Print-Top-Ten/m-p/715170#M693</guid>
      <dc:creator>Anonymous6</dc:creator>
      <dc:date>2021-01-29T04:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sort Data from Highest to Lowest and Print Top Ten Highest Salaries</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/How-to-Sort-Data-from-Highest-to-Lowest-and-Print-Top-Ten/m-p/715277#M696</link>
      <description>&lt;P&gt;To rephrase what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;is saying, the PROC PRINT is where the bug is.&amp;nbsp; The sort is saving the output into salaries_sort, so the print needs to be of salaries_sort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the PROC PRINT, change the DATA= option from DATA=MLB to DATA=salaries_sort&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 14:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/How-to-Sort-Data-from-Highest-to-Lowest-and-Print-Top-Ten/m-p/715277#M696</guid>
      <dc:creator>Al14</dc:creator>
      <dc:date>2021-01-29T14:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to Sort Data from Highest to Lowest and Print Top Ten Highest Salaries</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/How-to-Sort-Data-from-Highest-to-Lowest-and-Print-Top-Ten/m-p/715323#M698</link>
      <description>&lt;P&gt;I recommend not using PROC SORT and instead using PROC RANK, which then lets you specify how ties are handled. If you use PROC SORT, and the tenth and eleventh item are tied, then when you print out the Top 10, you miss the fact that there was a tie and you won't see the 11th item which has the same value as the 10th item.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=mlb ties=low out=mlb_ranked descending;
    var salaries;
    ranks salaries_ranked;
run;
proc print data=mlb_ranked(where=(salaries_ranked&amp;lt;=10));
  format Salary dollar12.3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above is one method of handling ties, the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=proc&amp;amp;docsetTarget=p16s2o8e4bnqrin1phywxdaxqba7.htm&amp;amp;locale=en#n128utp0vvfmlrn1lr0nbu0kf6nu" target="_self"&gt;PROC RANK documentation&lt;/A&gt; lists the other possible options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 15:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/How-to-Sort-Data-from-Highest-to-Lowest-and-Print-Top-Ten/m-p/715323#M698</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-29T15:38:08Z</dc:date>
    </item>
  </channel>
</rss>

