<?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: Sorting and grouping in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sorting-and-grouping/m-p/410719#M100360</link>
    <description>&lt;P&gt;You sorted by salary, but tried to print by country. When sorting by salary, you destroyed the country sequence.&lt;/P&gt;</description>
    <pubDate>Sun, 05 Nov 2017 20:57:47 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-11-05T20:57:47Z</dc:date>
    <item>
      <title>Sorting and grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-and-grouping/m-p/410716#M100359</link>
      <description>&lt;P&gt;I am a beginner to SAS. I am following the tutorials. I am confused on sorting and grouping.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc print data= orion.sales;
	by country;
run;&lt;/PRE&gt;&lt;P&gt;This code works well, and group the data set. When I run following code, it displays error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sort data=orion.sales
	out=work.sort_sales;
	by salary ;
run;

proc print data=work.sort_sales;
	by country;
Run;&lt;/PRE&gt;&lt;DIV class="sasError"&gt;ERROR: Data set WORK.SORT_SALES is not sorted in ascending sequence. The current BY group has Country = US and the next BY group&amp;nbsp;has Country = AU.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;I do not understand the reasoning behind having the same variable which we use to group by, in sorting statement.&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Thanks in advance.&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sun, 05 Nov 2017 20:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-and-grouping/m-p/410716#M100359</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2017-11-05T20:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting and grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-and-grouping/m-p/410719#M100360</link>
      <description>&lt;P&gt;You sorted by salary, but tried to print by country. When sorting by salary, you destroyed the country sequence.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Nov 2017 20:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-and-grouping/m-p/410719#M100360</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-05T20:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting and grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-and-grouping/m-p/410720#M100361</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I do not understand the reasoning behind having the same variable which we use to group by, in sorting statement.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;SAS processess data line by line, so when you use a BY statement&amp;nbsp;it expects the BY variables&amp;nbsp;to be in order in the data. To ensure this is the case, you would first need to sort the data to have that specified order. So the BY variable list needs to be the same in your SORT and then your BY statements in further&amp;nbsp;processes.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you need a more detailed explanation, I suggest reading through the&amp;nbsp;chapter on BY group processing in the&amp;nbsp;documentation.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0tq11jtmrhsd4n1co4p5tu1fbsi.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0tq11jtmrhsd4n1co4p5tu1fbsi.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Nov 2017 20:57:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-and-grouping/m-p/410720#M100361</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-05T20:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting and grouping</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-and-grouping/m-p/410722#M100363</link>
      <description>&lt;P&gt;Thank you so much for your quick reply. I will read the materials.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Nov 2017 21:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-and-grouping/m-p/410722#M100363</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2017-11-05T21:12:48Z</dc:date>
    </item>
  </channel>
</rss>

