<?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 Group the data sequencially based on ranks in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Group-the-data-sequencially-based-on-ranks/m-p/174621#M264573</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have divided the data into 10 groups based on ranks of a numerical variable ("var" here) - using proc rank.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I want to group the data into two groups sequentially based on the ranks:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first grouping would be: the first ranking group (o here) as one group, others as the other group;&lt;/P&gt;&lt;P&gt;The second grouping: the first two ranking groups as one group (0 and 1 here), other as the other group;&lt;/P&gt;&lt;P&gt;as so on, until the first 9 ranks is one group and the last rank is the other group;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also want the suffix of variable name is the ranking value. Or I may don't need the new group variable as long as I can identify the new groups., &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the data i have and what i want are simplified below:&lt;/P&gt;&lt;P&gt;==========================&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input class $ var rank;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;a 1&amp;nbsp; 0 &lt;/P&gt;&lt;P&gt;b 3&amp;nbsp; 2 &lt;/P&gt;&lt;P&gt;a 5&amp;nbsp; 2 &lt;/P&gt;&lt;P&gt;a 8&amp;nbsp; 3 &lt;/P&gt;&lt;P&gt;b 2&amp;nbsp; 1 &lt;/P&gt;&lt;P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gt;b 45 8 &amp;gt;0 &amp;gt;1&lt;/P&gt;&lt;P&gt;a 19 5 &amp;gt;0 &amp;gt;1&lt;/P&gt;&lt;P&gt;a 28 6 &amp;gt;0 &amp;gt;1&lt;/P&gt;&lt;P&gt;b 31 7 &amp;gt;0 &amp;gt;1&lt;/P&gt;&lt;P&gt;a 56 8 &amp;gt;0 &amp;gt;1&lt;/P&gt;&lt;P&gt;b 61 9 &amp;gt;0 &amp;gt;1&lt;/P&gt;&lt;P&gt;a 57 9 &amp;gt;0 &amp;gt;1&lt;/P&gt;&lt;P&gt;a 43 7 &amp;gt;0 &amp;gt;1&lt;/P&gt;&lt;P&gt;b 18 5 &amp;gt;0 &amp;gt;1&lt;/P&gt;&lt;P&gt;b 17 4 &amp;gt;0 &amp;gt;1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;=============================&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for help.&lt;/P&gt;&lt;P&gt;Z&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Dec 2013 16:47:43 GMT</pubDate>
    <dc:creator>imcbczm</dc:creator>
    <dc:date>2013-12-16T16:47:43Z</dc:date>
    <item>
      <title>Group the data sequencially based on ranks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-the-data-sequencially-based-on-ranks/m-p/174621#M264573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have divided the data into 10 groups based on ranks of a numerical variable ("var" here) - using proc rank.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I want to group the data into two groups sequentially based on the ranks:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first grouping would be: the first ranking group (o here) as one group, others as the other group;&lt;/P&gt;&lt;P&gt;The second grouping: the first two ranking groups as one group (0 and 1 here), other as the other group;&lt;/P&gt;&lt;P&gt;as so on, until the first 9 ranks is one group and the last rank is the other group;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also want the suffix of variable name is the ranking value. Or I may don't need the new group variable as long as I can identify the new groups., &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the data i have and what i want are simplified below:&lt;/P&gt;&lt;P&gt;==========================&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input class $ var rank;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;a 1&amp;nbsp; 0 &lt;/P&gt;&lt;P&gt;b 3&amp;nbsp; 2 &lt;/P&gt;&lt;P&gt;a 5&amp;nbsp; 2 &lt;/P&gt;&lt;P&gt;a 8&amp;nbsp; 3 &lt;/P&gt;&lt;P&gt;b 2&amp;nbsp; 1 &lt;/P&gt;&lt;P&gt;a 1&amp;nbsp; 0 &lt;/P&gt;&lt;P&gt;b 1&amp;nbsp; 0 &lt;/P&gt;&lt;P&gt;a 9&amp;nbsp; 3 &lt;/P&gt;&lt;P&gt;b 10 4 &lt;/P&gt;&lt;P&gt;a 21 6 &lt;/P&gt;&lt;P&gt;b 45 8 &lt;/P&gt;&lt;P&gt;a 19 5 &lt;/P&gt;&lt;P&gt;a 28 6 &lt;/P&gt;&lt;P&gt;b 31 7 &lt;/P&gt;&lt;P&gt;a 56 8 &lt;/P&gt;&lt;P&gt;b 61 9 &lt;/P&gt;&lt;P&gt;a 57 9 &lt;/P&gt;&lt;P&gt;a 43 7 &lt;/P&gt;&lt;P&gt;b 18 5 &lt;/P&gt;&lt;P&gt;b 17 4 &lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;input class $ var rank group0 $ group1 $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;a 1&amp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t;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Dec 2013 16:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-the-data-sequencially-based-on-ranks/m-p/174621#M264573</guid>
      <dc:creator>imcbczm</dc:creator>
      <dc:date>2013-12-16T16:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: Group the data sequencially based on ranks</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-the-data-sequencially-based-on-ranks/m-p/174622#M264574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't say what you'll do with this data but you may not need to add any variables at all. A group of custom formats applied to your rank variable may be all that you need unless you are explicitly going to do something with group1 and group0, in which case the formats are an easy way to create the variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;value group0&lt;/P&gt;&lt;P&gt;0 = '&amp;lt;=0'&lt;/P&gt;&lt;P&gt;1 - 9 = '&amp;gt;0';&lt;/P&gt;&lt;P&gt;value group1&lt;/P&gt;&lt;P&gt;0, 1 = '&amp;lt;=1'&lt;/P&gt;&lt;P&gt;2-9&amp;nbsp; = '&amp;gt;1'&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;value group2&lt;/P&gt;&lt;P&gt;0 - 2 = '&amp;lt;=2'&lt;/P&gt;&lt;P&gt;3- 9 = '&amp;gt;2'&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;/* continue in the hopefully obvious manner'&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group0 = put (rank,group0.); /*to create variables using the formats*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group1 = put 9rank,group1.);&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or&lt;/P&gt;&lt;P&gt;proc freq data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables rank;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format rank group0.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Most analysis programs will honor the format for analysis.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Dec 2013 18:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-the-data-sequencially-based-on-ranks/m-p/174622#M264574</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-12-16T18:29:26Z</dc:date>
    </item>
  </channel>
</rss>

