<?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 dates within cases in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864108#M341275</link>
    <description>&lt;P&gt;Did you read the documentation of PROC RANK?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p16s2o8e4bnqrin1phywxdaxqba7.htm#n128utp0vvfmlrn1lr0nbu0kf6nu" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p16s2o8e4bnqrin1phywxdaxqba7.htm#n128utp0vvfmlrn1lr0nbu0kf6nu&lt;/A&gt;&lt;/P&gt;
&lt;H4 class="xisDoc-argument"&gt;TIES=&lt;SPAN class="xisDoc-choice"&gt;HIGH&lt;/SPAN&gt;&lt;SPAN class="xisDoc-choice"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;| LOW&lt;/SPAN&gt;&lt;SPAN class="xisDoc-choice"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;| MEAN&lt;/SPAN&gt;&lt;SPAN class="xisDoc-choice"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;| DENSE&lt;/SPAN&gt;&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P&gt;&lt;SPAN class="xisDoc-shortDescription"&gt;specifies how to compute normal scores or ranks for tied data values.&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV id="n165gw9igkhl2ln19p8tjd3uweh3" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;HIGH&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;assigns the largest of the corresponding ranks (or largest of the normal scores when NORMAL= is specified).&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV id="p1s9kr5fgd2brgn1kariq2xmocl9" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;LOW&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;assigns the smallest of the corresponding ranks (or smallest of the normal scores when NORMAL= is specified).&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV id="n1ft3sydzrb8s2n1n18pdbgm30kn" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;MEAN&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;assigns the mean of the corresponding rank (or mean of the normal scores when NORMAL= is specified).&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV id="n03ccw4ijqs5i5n11l4ju63vhyfs" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;DENSE&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;computes scores and ranks by treating tied values as a single-order statistic. For the default method, ranks are consecutive integers that begin with the number one and end with the number of unique, nonmissing values of the variable that is being ranked. Tied values are assigned the same rank.&lt;/P&gt;
&lt;DIV id="p02n7b0ye5bbawn1bx0b4pdctknj" class="xisDoc-note"&gt;&lt;SPAN class="xisDoc-noteGenText"&gt;Note:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;CONDENSE is an alias for DENSE.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Tue, 14 Mar 2023 17:27:32 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-03-14T17:27:32Z</dc:date>
    <item>
      <title>rank dates within cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864099#M341270</link>
      <description>&lt;P&gt;I ran into a challenge, hope experts can advise.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In a data set, we have case IDs (1, 2, etc), and the next column is dates of accident:&lt;/P&gt;&lt;P&gt;1.00 06/04/2008&lt;BR /&gt;1.00 06/08/2008&lt;BR /&gt;2.00 06/14/2008&lt;BR /&gt;3.00 08/23/2008&lt;BR /&gt;3.00 08/23/2008&lt;BR /&gt;4.00 08/23/2008&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here, if the date is the same withing the same ID, it is the same accident. So for ID=3, it will be the same accident, just 2 records for different aspects of the accident.&lt;/P&gt;&lt;P&gt;We need to assign a number to each unique accident. So for ID=1, it will be 1 and 2. For ID=2, will be 1. For&amp;nbsp; ID=3, 1 and 2. And for ID=4, 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue is that when I use a rank function to rank dates by ID, the result is weird. For some cases, the rank is 11.5, 23.5 etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to make it work so that for each case ID it will rank order just the dates within that ID?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 15:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864099#M341270</guid>
      <dc:creator>Nia2023</dc:creator>
      <dc:date>2023-03-14T15:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: rank dates within cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864100#M341271</link>
      <description>&lt;P&gt;Just a simple numbering of the cases should work.&amp;nbsp; Just increment the number every time you see a new date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have ;
  by id date;
  if first.id then casenum=0;
  casenum + first.date ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Mar 2023 16:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864100#M341271</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-14T16:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: rank dates within cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864104#M341273</link>
      <description>&lt;P&gt;It sounds like you used proc rank which will deal with ties in a number of ways depending on the options chosen. The default is MEAN which would tend to generate values with a .5 when there are two identical dates. One suspect that you did not use a BY ID for the range of values mention.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps: May need to sort by ID and date if not actually so in your data.&lt;/P&gt;
&lt;PRE&gt;data have;
   input id date :mmddyy10.;
   format date mmddyy10.;
datalines;
1.00 06/04/2008
1.00 06/08/2008
2.00 06/14/2008
3.00 08/23/2008
3.00 08/23/2008
4.00 08/23/2008
;

proc rank data=have out=ranked ties=low;
   by id;
   ranks daterank;
   var date ;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note your description "So for ID=3, it will be the same accident, just 2 records for different aspects of the accident.&lt;/P&gt;
&lt;P&gt;.... For ID=3, 1 and 2." seems inconsistent. Wouldn't "same accident" be the same rank?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 16:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864104#M341273</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-14T16:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: rank dates within cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864107#M341274</link>
      <description>&lt;P&gt;Thank you! Yes, you are right - for ID=3, should be 1 for both dates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your solution. It gets rid of .5 values. However, it does not assign the values consecutively, which is evident when the number of accidents is higher:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rank&lt;/P&gt;&lt;P&gt;10.00 09/19/2006 1.00&lt;BR /&gt;10.00 09/19/2006 1.00&lt;BR /&gt;10.00 10/17/2006 5.00&lt;BR /&gt;10.00 10/17/2006 5.00&lt;BR /&gt;10.00 10/30/2006 8.00&lt;BR /&gt;10.00 10/30/2006 8.00&lt;BR /&gt;10.00 11/06/2006 11.00&lt;BR /&gt;10.00 11/06/2006 11.00&lt;BR /&gt;10.00 12/13/2006 13.00&lt;BR /&gt;10.00 12/13/2006 13.00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead, we need:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rank&lt;/P&gt;&lt;P&gt;10.00 09/19/2006 1.00&lt;BR /&gt;10.00 09/19/2006 1.00&lt;BR /&gt;10.00 10/17/2006 2.00&lt;BR /&gt;10.00 10/17/2006 2.00&lt;BR /&gt;10.00 10/30/2006 3.00&lt;BR /&gt;10.00 10/30/2006 3.00&lt;/P&gt;&lt;P&gt;10.00 10/30/2006 3.00&lt;BR /&gt;10.00 11/06/2006 4.00&lt;BR /&gt;10.00 11/06/2006 4.00&lt;BR /&gt;10.00 12/13/2006 5.00&lt;BR /&gt;10.00 12/13/2006 5.00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for ID=10 there were 5 distinct accidents in total, and should be numbered 1-5, not 1-13.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do that?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 17:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864107#M341274</guid>
      <dc:creator>Nia2023</dc:creator>
      <dc:date>2023-03-14T17:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: rank dates within cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864108#M341275</link>
      <description>&lt;P&gt;Did you read the documentation of PROC RANK?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p16s2o8e4bnqrin1phywxdaxqba7.htm#n128utp0vvfmlrn1lr0nbu0kf6nu" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p16s2o8e4bnqrin1phywxdaxqba7.htm#n128utp0vvfmlrn1lr0nbu0kf6nu&lt;/A&gt;&lt;/P&gt;
&lt;H4 class="xisDoc-argument"&gt;TIES=&lt;SPAN class="xisDoc-choice"&gt;HIGH&lt;/SPAN&gt;&lt;SPAN class="xisDoc-choice"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;| LOW&lt;/SPAN&gt;&lt;SPAN class="xisDoc-choice"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;| MEAN&lt;/SPAN&gt;&lt;SPAN class="xisDoc-choice"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;| DENSE&lt;/SPAN&gt;&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P&gt;&lt;SPAN class="xisDoc-shortDescription"&gt;specifies how to compute normal scores or ranks for tied data values.&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV id="n165gw9igkhl2ln19p8tjd3uweh3" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;HIGH&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;assigns the largest of the corresponding ranks (or largest of the normal scores when NORMAL= is specified).&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV id="p1s9kr5fgd2brgn1kariq2xmocl9" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;LOW&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;assigns the smallest of the corresponding ranks (or smallest of the normal scores when NORMAL= is specified).&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV id="n1ft3sydzrb8s2n1n18pdbgm30kn" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;MEAN&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;assigns the mean of the corresponding rank (or mean of the normal scores when NORMAL= is specified).&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV id="n03ccw4ijqs5i5n11l4ju63vhyfs" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;DENSE&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;computes scores and ranks by treating tied values as a single-order statistic. For the default method, ranks are consecutive integers that begin with the number one and end with the number of unique, nonmissing values of the variable that is being ranked. Tied values are assigned the same rank.&lt;/P&gt;
&lt;DIV id="p02n7b0ye5bbawn1bx0b4pdctknj" class="xisDoc-note"&gt;&lt;SPAN class="xisDoc-noteGenText"&gt;Note:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;CONDENSE is an alias for DENSE.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 14 Mar 2023 17:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864108#M341275</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-14T17:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: rank dates within cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864122#M341280</link>
      <description>&lt;P&gt;It did work with the Dense option produced what we wanted.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you so much, I greatly appreciate your help!!!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 18:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864122#M341280</guid>
      <dc:creator>Nia2023</dc:creator>
      <dc:date>2023-03-14T18:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: rank dates within cases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864131#M341283</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/440791"&gt;@Nia2023&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you! Yes, you are right - for ID=3, should be 1 for both dates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried your solution. It gets rid of .5 values. However, it does not assign the values consecutively, which is evident when the number of accidents is higher:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rank&lt;/P&gt;
&lt;P&gt;10.00 09/19/2006 1.00&lt;BR /&gt;10.00 09/19/2006 1.00&lt;BR /&gt;10.00 10/17/2006 5.00&lt;BR /&gt;10.00 10/17/2006 5.00&lt;BR /&gt;10.00 10/30/2006 8.00&lt;BR /&gt;10.00 10/30/2006 8.00&lt;BR /&gt;10.00 11/06/2006 11.00&lt;BR /&gt;10.00 11/06/2006 11.00&lt;BR /&gt;10.00 12/13/2006 13.00&lt;BR /&gt;10.00 12/13/2006 13.00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, we need:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rank&lt;/P&gt;
&lt;P&gt;10.00 09/19/2006 1.00&lt;BR /&gt;10.00 09/19/2006 1.00&lt;BR /&gt;10.00 10/17/2006 2.00&lt;BR /&gt;10.00 10/17/2006 2.00&lt;BR /&gt;10.00 10/30/2006 3.00&lt;BR /&gt;10.00 10/30/2006 3.00&lt;/P&gt;
&lt;P&gt;10.00 10/30/2006 3.00&lt;BR /&gt;10.00 11/06/2006 4.00&lt;BR /&gt;10.00 11/06/2006 4.00&lt;BR /&gt;10.00 12/13/2006 5.00&lt;BR /&gt;10.00 12/13/2006 5.00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for ID=10 there were 5 distinct accidents in total, and should be numbered 1-5, not 1-13.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to do that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do please compare your first example with this data as well. You can oversimplify as in this case.&amp;nbsp; Also, any time you get a result that doesn't match your expectations then show the CODE that you use as well as data.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 18:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rank-dates-within-cases/m-p/864131#M341283</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-14T18:16:06Z</dc:date>
    </item>
  </channel>
</rss>

