<?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 Finding the 5th occurrence of an ID in a column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/733733#M228631</link>
    <description>&lt;P&gt;Hello I have a data set which has a variable ID with the client ID. I want to identify the fifth occurrence of that ID. For example if my data set looks like this I want to populate a variable called "INDICATOR" which will populate a value of 1 on the fifth occurrence. I know of the function first where I could use first.ID to do this for the first time the ID shows up, but is there a fifth function as well? Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; NAME INDICATOR&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp; apple&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp;&amp;nbsp;apple&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp;&amp;nbsp;apple&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp;&amp;nbsp;apple&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp;&amp;nbsp;apple&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;023&amp;nbsp; &amp;nbsp; bb&lt;/P&gt;&lt;P&gt;023&amp;nbsp; &amp;nbsp; bb&lt;/P&gt;&lt;P&gt;023&amp;nbsp; &amp;nbsp; bb&lt;/P&gt;&lt;P&gt;023&amp;nbsp; &amp;nbsp; bb&lt;/P&gt;&lt;P&gt;023&amp;nbsp; &amp;nbsp; bb&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Apr 2021 13:19:39 GMT</pubDate>
    <dc:creator>themanwith2thum</dc:creator>
    <dc:date>2021-04-14T13:19:39Z</dc:date>
    <item>
      <title>Finding the 5th occurrence of an ID in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/733733#M228631</link>
      <description>&lt;P&gt;Hello I have a data set which has a variable ID with the client ID. I want to identify the fifth occurrence of that ID. For example if my data set looks like this I want to populate a variable called "INDICATOR" which will populate a value of 1 on the fifth occurrence. I know of the function first where I could use first.ID to do this for the first time the ID shows up, but is there a fifth function as well? Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; NAME INDICATOR&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp; apple&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp;&amp;nbsp;apple&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp;&amp;nbsp;apple&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp;&amp;nbsp;apple&lt;/P&gt;&lt;P&gt;001&amp;nbsp; &amp;nbsp;&amp;nbsp;apple&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;023&amp;nbsp; &amp;nbsp; bb&lt;/P&gt;&lt;P&gt;023&amp;nbsp; &amp;nbsp; bb&lt;/P&gt;&lt;P&gt;023&amp;nbsp; &amp;nbsp; bb&lt;/P&gt;&lt;P&gt;023&amp;nbsp; &amp;nbsp; bb&lt;/P&gt;&lt;P&gt;023&amp;nbsp; &amp;nbsp; bb&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 13:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/733733#M228631</guid>
      <dc:creator>themanwith2thum</dc:creator>
      <dc:date>2021-04-14T13:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the 5th occurrence of an ID in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/733738#M228633</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by id;
if first.id
then count = 1;
else count + 1;
if count = 5 then indicator = 1;
drop count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SUM statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count + 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;causes an implicit RETAIN of count.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 13:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/733738#M228633</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-14T13:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the 5th occurrence of an ID in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/733739#M228634</link>
      <description>&lt;P&gt;There is no "fifth" function, but you can easily just count and create the indicator variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */
data want; 
    set have;
    by id;
    if first.id then count=0;
    count+1;
    if count=5 then flag=1;
    drop count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Apr 2021 13:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/733739#M228634</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-14T13:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the 5th occurrence of an ID in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/733740#M228635</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by id;
  if first.id then counter=1;
  else counter+1;
  if counter=5 then put 'found 5th occurrence at ' _n_=  (_all_) (=);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Apr 2021 13:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/733740#M228635</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-14T13:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the 5th occurrence of an ID in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/733761#M228639</link>
      <description>&lt;P&gt;Question: is it the "fifth" occurrence or the LAST? Your example appears to be asking for a last that just happens to be "fifth".&lt;/P&gt;
&lt;P&gt;If not you should build examples that show 1) at least 6 elements and 2) what you expect if there are only fewer than 5 for an id and indicator combination.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 14:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/733761#M228639</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-14T14:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the 5th occurrence of an ID in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/734457#M228804</link>
      <description>&lt;P&gt;Is the data always sorted or grouped by ID?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 19:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-5th-occurrence-of-an-ID-in-a-column/m-p/734457#M228804</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-04-15T19:36:02Z</dc:date>
    </item>
  </channel>
</rss>

