<?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: Reordering groups when condition is met in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/698149#M213485</link>
    <description>&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" size="4"&gt;Thanks for your quick response.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" size="4"&gt;It's OK now.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" size="4"&gt;I managed to get the desired output by doing some slight adjustment in datastep and using proc sort.&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Nov 2020 14:22:12 GMT</pubDate>
    <dc:creator>Miracle</dc:creator>
    <dc:date>2020-11-11T14:22:12Z</dc:date>
    <item>
      <title>Reordering groups when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/697555#M213197</link>
      <description>&lt;P&gt;&lt;FONT face="andale mono,times"&gt;Dear All,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;Can I please seek your help on how to achieve this?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times"&gt;When group=ZZZ has the same freq to other groups (in this case group=XYZ and STU which will change depending on the time point of data extraction)&amp;nbsp; we are required to always present group=ZZZ as the last group before the next group with reduced freq (in this case, MNO 30).&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;Thanks a lot.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times"&gt;Let say the following is my input data.&lt;/FONT&gt;&lt;FONT face="andale mono,times" size="4"&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE width="128"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;group&lt;/TD&gt;
&lt;TD width="64"&gt;freq&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ABC&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;CDE&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;FGH&lt;/TD&gt;
&lt;TD&gt;45&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;IJK&lt;/TD&gt;
&lt;TD&gt;46&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ZZZ&lt;/TD&gt;
&lt;TD&gt;43&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;XYZ&lt;/TD&gt;
&lt;TD&gt;43&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;STU&lt;/TD&gt;
&lt;TD&gt;43&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MNO&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;FONT face="andale mono,times"&gt;How do I achieve the following the data? [PREVIOUS]&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE width="128"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;group&lt;/TD&gt;
&lt;TD width="64"&gt;freq&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ABC&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;CDE&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;FGH&lt;/TD&gt;
&lt;TD&gt;45&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;IJK&lt;/TD&gt;
&lt;TD&gt;46&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;XYZ&lt;/TD&gt;
&lt;TD&gt;43&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;STU&lt;/TD&gt;
&lt;TD&gt;43&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ZZZ&lt;/TD&gt;
&lt;TD&gt;43&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;MNO&lt;/TD&gt;
&lt;TD&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times"&gt;How do I achieve the following the data? [CURRENT]&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;group&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;freq&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;ABC&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;CDE&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;50&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;FGH&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;45&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;IJK&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;46&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;XYZ&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;43&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;STU&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;43&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;ZZZ&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;43&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;MNO&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;BBC&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;CCN&lt;/TD&gt;
&lt;TD align="right"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" class="xl63" style="height: 12.75pt; width: 48pt;"&gt;JKL&lt;/TD&gt;
&lt;TD width="64" align="right" class="xl63" style="width: 48pt;"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;FONT face="andale mono,times"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 11:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/697555#M213197</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2020-11-11T11:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering groups when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/697558#M213198</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input group $ 1-3 freq;
datalines;
ABC	100
CDE 50 
FGH 45 
IJK 46 
ZZZ	43 
XYZ	43 
STU	43 
MNO 30 
;

proc sql;
   create table want as
   select * from have
   order by freq desc, group = "ZZZ";
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;group freq 
ABC   100 
CDE   50 
IJK   46 
FGH   45 
STU   43 
XYZ   43 
ZZZ   43 
MNO   30 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 10:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/697558#M213198</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-09T10:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering groups when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/697561#M213199</link>
      <description>&lt;P&gt;Given your group names, this is the quickest way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort
  data=have
  out=want
;
by descending freq group;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Nov 2020 10:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/697561#M213199</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-09T10:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering groups when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/697592#M213212</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; for your quick help&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 12:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/697592#M213212</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2020-11-09T12:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering groups when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/698118#M213470</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;.&lt;BR /&gt;Thanks but it doesn't work for current case.&lt;BR /&gt;How do we do achieve given the current case please?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 11:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/698118#M213470</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2020-11-11T11:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering groups when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/698126#M213473</link>
      <description>&lt;P&gt;You need to supply the source data for your second expected result. Since we have shown you how to do it, supply it as a data step with datalines.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 11:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/698126#M213473</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-11T11:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering groups when condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/698149#M213485</link>
      <description>&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" size="4"&gt;Thanks for your quick response.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" size="4"&gt;It's OK now.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" size="4"&gt;I managed to get the desired output by doing some slight adjustment in datastep and using proc sort.&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 14:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-groups-when-condition-is-met/m-p/698149#M213485</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2020-11-11T14:22:12Z</dc:date>
    </item>
  </channel>
</rss>

