<?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: Rank variables by group in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Rank-variables-by-group/m-p/885075#M82842</link>
    <description>&lt;P&gt;You can sort the data by descending count, then take the first 3 records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you can use PROC RANK and just keep the records where the rank is less than or equal to 3.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=have descending out=want ties=low;
     by month;
     var num;
     ranks num_ranked;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: these two methods will not produce the same results in the case of ties.&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jul 2023 14:16:24 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-07-17T14:16:24Z</dc:date>
    <item>
      <title>Rank variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rank-variables-by-group/m-p/885071#M82841</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;I'm trying to find the rank for the different count on values by month and year and to have first 3 positions (descending by num) for the each month. I have only one year data. Help me please to this in right way.&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;month=1; code='BB1111111'; year=2023; name='BB'; num=4; output;&lt;BR /&gt;month=1; code='AA1111111'; year=2023; name='AA'; num=8; output;&lt;BR /&gt;month=1; code='FF1111111'; year=2023; name='FF'; num=1; output;&lt;BR /&gt;month=1; code='CC1111111'; year=2023; name='CC'; num=5134; output;&lt;BR /&gt;month=1; code='DD1111111'; tyear=2023; name='DD'; num=525; output;&lt;BR /&gt;month=1; code='EE1111111'; year=2023; name='EE'; num=125; output;&lt;BR /&gt;month=2; code='QQ1111111'; year=2023; name='QQ'; num=4; output;&lt;BR /&gt;month=2; code='CC1111111'; tyear=2023; name='CC'; num=5321; output;&lt;BR /&gt;month=2; code='DD1111111'; year=2023; name='DD'; num=256; output;&lt;BR /&gt;month=2; code='WW1111111'; year=2023;name='&lt;SPAN&gt;WW'; num=151; output;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;month=3; code='BB1111111'; year=2023; name='AA'; num=12; output;&lt;BR /&gt;month=3; code='CC1111111'; year=2023; name='CC'; num=2860; output;&lt;BR /&gt;month=3; code='CC1111111'; year=2023; name='DD'; num=655; output;&lt;BR /&gt;month=3; code='CC1111111'; year=2023; name='EE'; num=62; output;&lt;BR /&gt;month=4; code='AA1111111'; year=2023; name='AA'; num=2; output;&lt;BR /&gt;month=4; code='BB1111111'; year=2023; name='BB'; num=12; output;&lt;BR /&gt;month=4; code='CC1111111'; year=2023;name='CC'; num=1962; output;&lt;BR /&gt;month=4; code='CC1111111'; tyear=2023;name='DD'; num=865; output;&lt;BR /&gt;month=4; code='CC1111111'; year=2023;name='EE'; num=112; output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output I need:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD height="30px"&gt;month&lt;/TD&gt;
&lt;TD height="30px"&gt;year&lt;/TD&gt;
&lt;TD height="30px"&gt;code&lt;/TD&gt;
&lt;TD height="30px"&gt;
&lt;P&gt;name&lt;/P&gt;
&lt;/TD&gt;
&lt;TD height="30px"&gt;num&lt;/TD&gt;
&lt;TD height="30px"&gt;rank&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;2023&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;CC1111111&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;CC&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;5134&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;1&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;2023&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;DD1111111&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;DD&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;525&lt;/TD&gt;
&lt;TD width="16.666666666666668%" height="30px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="30px"&gt;1&lt;/TD&gt;
&lt;TD height="30px"&gt;2023&lt;/TD&gt;
&lt;TD height="30px"&gt;EE1111111&lt;/TD&gt;
&lt;TD height="30px"&gt;EE&lt;/TD&gt;
&lt;TD height="30px"&gt;125&lt;/TD&gt;
&lt;TD height="30px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="30px"&gt;2&lt;/TD&gt;
&lt;TD height="30px"&gt;2023&lt;/TD&gt;
&lt;TD height="30px"&gt;CC1111111&lt;/TD&gt;
&lt;TD height="30px"&gt;CC&lt;/TD&gt;
&lt;TD height="30px"&gt;5321&lt;/TD&gt;
&lt;TD height="30px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="30px"&gt;2&lt;/TD&gt;
&lt;TD height="30px"&gt;2023&lt;/TD&gt;
&lt;TD height="30px"&gt;DD1111111&lt;/TD&gt;
&lt;TD height="30px"&gt;DD&lt;/TD&gt;
&lt;TD height="30px"&gt;256&lt;/TD&gt;
&lt;TD height="30px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="30px"&gt;2&lt;/TD&gt;
&lt;TD height="30px"&gt;2023&lt;/TD&gt;
&lt;TD height="30px"&gt;WW1111111&lt;/TD&gt;
&lt;TD height="30px"&gt;WW&lt;/TD&gt;
&lt;TD height="30px"&gt;151&lt;/TD&gt;
&lt;TD height="30px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="30px"&gt;etc.&lt;/TD&gt;
&lt;TD height="30px"&gt;...&lt;/TD&gt;
&lt;TD height="30px"&gt;...&lt;/TD&gt;
&lt;TD height="30px"&gt;...&lt;/TD&gt;
&lt;TD height="30px"&gt;...&lt;/TD&gt;
&lt;TD height="30px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 13:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rank-variables-by-group/m-p/885071#M82841</guid>
      <dc:creator>J_J_J</dc:creator>
      <dc:date>2023-07-17T13:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Rank variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rank-variables-by-group/m-p/885075#M82842</link>
      <description>&lt;P&gt;You can sort the data by descending count, then take the first 3 records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you can use PROC RANK and just keep the records where the rank is less than or equal to 3.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=have descending out=want ties=low;
     by month;
     var num;
     ranks num_ranked;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: these two methods will not produce the same results in the case of ties.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 14:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rank-variables-by-group/m-p/885075#M82842</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-17T14:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Rank variables by group</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rank-variables-by-group/m-p/885077#M82843</link>
      <description>Thank you, Paige Miller!</description>
      <pubDate>Mon, 17 Jul 2023 14:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rank-variables-by-group/m-p/885077#M82843</guid>
      <dc:creator>J_J_J</dc:creator>
      <dc:date>2023-07-17T14:22:04Z</dc:date>
    </item>
  </channel>
</rss>

