<?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: Ascending and Descending in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Ascending-and-Descending/m-p/401680#M3606</link>
    <description>&lt;P&gt;What prints out?&lt;/P&gt;
&lt;P&gt;Your first sort works as you intend, however when you run the second sort that changes the data.&amp;nbsp; What is it you want, just the last record per group?&amp;nbsp; Then:&lt;/P&gt;
&lt;PRE&gt;proc sort data=emails;
  by ch_phpartyid sourcesystemclient descending created;
run;

data want;
  set emails
  by ch_phpartyid sourcesystemclient descending created;
  if last.ch_phpartyid;
run;&lt;/PRE&gt;
&lt;P&gt;Do note how I use formatting, consistent casing, indentations etc. to make the code easy to read.&lt;/P&gt;</description>
    <pubDate>Fri, 06 Oct 2017 10:15:48 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-10-06T10:15:48Z</dc:date>
    <item>
      <title>Ascending and Descending</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Ascending-and-Descending/m-p/401674#M3605</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I encounter this issue where I am sorting the data.&lt;BR /&gt;The following is the procedure;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15654i26D1B680CD904C32/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.PNG" alt="1.PNG" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;The following is a sample data i used;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15655iC43B882A5C05E326/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.PNG" alt="2.PNG" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Based on my understanding, it should print out the second row because CREATED is sorting in descending order.&lt;BR /&gt;But the result i got is completely different, it prints out the one in between.&lt;BR /&gt;As follow;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3.PNG" style="width: 356px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15656iA0E07D7661B23213/image-size/large?v=v2&amp;amp;px=999" role="button" title="3.PNG" alt="3.PNG" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Please provide me with some insights into this matter!&lt;BR /&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 09:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Ascending-and-Descending/m-p/401674#M3605</guid>
      <dc:creator>Wken1122</dc:creator>
      <dc:date>2017-10-06T09:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending and Descending</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Ascending-and-Descending/m-p/401680#M3606</link>
      <description>&lt;P&gt;What prints out?&lt;/P&gt;
&lt;P&gt;Your first sort works as you intend, however when you run the second sort that changes the data.&amp;nbsp; What is it you want, just the last record per group?&amp;nbsp; Then:&lt;/P&gt;
&lt;PRE&gt;proc sort data=emails;
  by ch_phpartyid sourcesystemclient descending created;
run;

data want;
  set emails
  by ch_phpartyid sourcesystemclient descending created;
  if last.ch_phpartyid;
run;&lt;/PRE&gt;
&lt;P&gt;Do note how I use formatting, consistent casing, indentations etc. to make the code easy to read.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 10:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Ascending-and-Descending/m-p/401680#M3606</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-06T10:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending and Descending</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Ascending-and-Descending/m-p/401682#M3607</link>
      <description>&lt;P&gt;Don't rely on SAS preserving the order within the groups. This can be dependent on the type of SAS storage.&lt;/P&gt;
&lt;P&gt;Do this as your second step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_emails;
set emails;
by ch_phpartyid sourcesystemclient;
if first.sourcesystemclient;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW, don't post code as a picture. Copy/paste the text to a code window ("little running man" or {i} icon). It saves us re-typing the code.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 10:18:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Ascending-and-Descending/m-p/401682#M3607</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-06T10:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending and Descending</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Ascending-and-Descending/m-p/401790#M3608</link>
      <description>&lt;P&gt;This may seem a silly question but is your Created variable numeric or character? If it is character then you will get all the day 31 records first, then day 30, then day 29 as character&amp;nbsp;variables will sort differently than an actual Datetime variable. Since your value shown has a space between the year and the time component it is very likely that variable is character as most of the SAS datetime display formats do not include that space.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 14:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Ascending-and-Descending/m-p/401790#M3608</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-06T14:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending and Descending</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Ascending-and-Descending/m-p/402289#M3630</link>
      <description>&lt;P&gt;But the thing is, if Created is sorted in descending order then why would 18/8/2016's row appears in the sorted table instead of 6/10/2016?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 07:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Ascending-and-Descending/m-p/402289#M3630</guid>
      <dc:creator>Wken1122</dc:creator>
      <dc:date>2017-10-09T07:04:50Z</dc:date>
    </item>
  </channel>
</rss>

