<?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: Enumerate unique value by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/615837#M180175</link>
    <description>&lt;P&gt;Alternatively, since it is sweetly sorted, you could have some fun like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input id       date  :yymmdd8.; 
format date yymmdd10.; 
cards;
123   20190101    1
123   20190101    1
123   20190102    2 
123    20190102    2
;

data want_ranked;
 do _n_=1 by 1 until(last.id);
  do until(last.date);
   set have;
    by id date;
	ranked_date=_n_;
	output;
  end;
 end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*Or*/&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_ranked;
 set have;
 by id date;
 if first.id then ranked_date=1;
 else if first.date then ranked_date+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want_ranked as
select  a.* ,count(distinct  b.date) as ranked_date
from have a inner join (select distinct id,date from have) b
on a.id=b.id and b.date&amp;lt;=a.date	
group by a.id,a.date
having max(b.date)=b.date
order by a.id,a.date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jan 2020 01:18:49 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-01-08T01:18:49Z</dc:date>
    <item>
      <title>Enumerate unique value by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/615834#M180172</link>
      <description>&lt;P&gt;Hi, I'm having a question regarding how to enumerate unique date by group - id, see below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id. &amp;nbsp; &amp;nbsp; &amp;nbsp; date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; rank&lt;/P&gt;&lt;P&gt;123. &amp;nbsp; 20190101. &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;123. &amp;nbsp;&amp;nbsp;20190101. &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;123. &amp;nbsp; 20190102. &amp;nbsp; &amp;nbsp;2&amp;nbsp;&lt;/P&gt;&lt;P&gt;123 &amp;nbsp; &amp;nbsp;20190102. &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how do I get the rank column?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 00:24:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/615834#M180172</guid>
      <dc:creator>inyli</dc:creator>
      <dc:date>2020-01-08T00:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: Enumerate unique value by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/615836#M180174</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id       date  :yymmdd8.; 
format date yymmdd10.; 
cards;
123   20190101    1
123   20190101    1
123   20190102    2 
123    20190102    2
;

proc rank data=have out=ranked ties=dense ; 
 by id;
 var date;
 ranks ranked_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;123 2019-01-01 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;123 2019-01-01 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;123 2019-01-02 2&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;123 2019-01-02 2&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 00:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/615836#M180174</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-08T00:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Enumerate unique value by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/615837#M180175</link>
      <description>&lt;P&gt;Alternatively, since it is sweetly sorted, you could have some fun like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input id       date  :yymmdd8.; 
format date yymmdd10.; 
cards;
123   20190101    1
123   20190101    1
123   20190102    2 
123    20190102    2
;

data want_ranked;
 do _n_=1 by 1 until(last.id);
  do until(last.date);
   set have;
    by id date;
	ranked_date=_n_;
	output;
  end;
 end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*Or*/&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_ranked;
 set have;
 by id date;
 if first.id then ranked_date=1;
 else if first.date then ranked_date+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want_ranked as
select  a.* ,count(distinct  b.date) as ranked_date
from have a inner join (select distinct id,date from have) b
on a.id=b.id and b.date&amp;lt;=a.date	
group by a.id,a.date
having max(b.date)=b.date
order by a.id,a.date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 01:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/615837#M180175</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-08T01:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: Enumerate unique value by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/615958#M180245</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/305980"&gt;@inyli&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	by id date;
	if first.id then flag = 0;
	if first.date then flag + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Jan 2020 15:26:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/615958#M180245</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-08T15:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Enumerate unique value by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/616184#M180361</link>
      <description>Thanks!!!!</description>
      <pubDate>Thu, 09 Jan 2020 13:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/616184#M180361</guid>
      <dc:creator>inyli</dc:creator>
      <dc:date>2020-01-09T13:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Enumerate unique value by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/616185#M180362</link>
      <description>Thank you! It works:)</description>
      <pubDate>Thu, 09 Jan 2020 13:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Enumerate-unique-value-by-group/m-p/616185#M180362</guid>
      <dc:creator>inyli</dc:creator>
      <dc:date>2020-01-09T13:24:14Z</dc:date>
    </item>
  </channel>
</rss>

