<?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: Create counter in increments of i by subgroup in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-counter-in-increments-of-i-by-subgroup/m-p/293888#M61256</link>
    <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by year;
   retain count_up_by_five rowcount 0;
   if first.year then do;
      count_up_by_five=1;
      rowcount=1;
   end;
   else rowcount+1;
   output;
   if mod(rowcount,5)=0 then count_up_by_five+1;
   drop rowcount;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Change the 5 in the Mod(rowcount,5) to do other size groups. DO not use 1 or 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Aug 2016 23:02:28 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-08-24T23:02:28Z</dc:date>
    <item>
      <title>Create counter in increments of i by subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-counter-in-increments-of-i-by-subgroup/m-p/293872#M61246</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to ask for your support on the following issue, illustrated via an example:&lt;BR /&gt;Let the database contain multiple observations for each year (multiple rows with the same value for the "year" variable). For each year in the database, I would like to create a variable which counts forward.&lt;BR /&gt;For 2000, it starts with 1, proceeds to 2 and so on.&lt;/P&gt;&lt;P&gt;This procedure shall be restarted the next year. Thus, in 2001, the first observation of 2001 would get a 1, the second a 2, and so on...&lt;/P&gt;&lt;P&gt;But now, I do not want the counter to add a 1 in each increment. It shall stand still for e.g. 5 steps.&lt;/P&gt;&lt;P&gt;I.e., the first five observations of year 2000 would all get a 1. The next five a 2. Then, there may be only three observations left for year 2000, but they still get "their" 3.&lt;/P&gt;&lt;P&gt;This data gives an example of what I am thinking of.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-SPOILER&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	infile datalines dlm=',' truncover;
	input year count_up_by_five;
	datalines;
		2000,1
		2000,1
		2000,1
		2000,1
		2000,1
		2000,2
		2000,2
		2000,2
		2000,2
		2000,2
		2000,3
		2000,3
		2000,3
		2001,1
		2001,1
		2001,1
		2001,1
		2001,1
		2001,2
		2001,2
		2001,2
		2001,2
		2001,2
		2001,3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI-SPOILER&gt;&lt;P&gt;I would be glad if you could help me with this issue of mine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yours sincerely,&lt;/P&gt;&lt;P&gt;Sinistrum&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2016 21:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-counter-in-increments-of-i-by-subgroup/m-p/293872#M61246</guid>
      <dc:creator>Sinistrum</dc:creator>
      <dc:date>2016-08-24T21:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Create counter in increments of i by subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-counter-in-increments-of-i-by-subgroup/m-p/293888#M61256</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by year;
   retain count_up_by_five rowcount 0;
   if first.year then do;
      count_up_by_five=1;
      rowcount=1;
   end;
   else rowcount+1;
   output;
   if mod(rowcount,5)=0 then count_up_by_five+1;
   drop rowcount;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Change the 5 in the Mod(rowcount,5) to do other size groups. DO not use 1 or 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2016 23:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-counter-in-increments-of-i-by-subgroup/m-p/293888#M61256</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-24T23:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create counter in increments of i by subgroup</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-counter-in-increments-of-i-by-subgroup/m-p/293969#M61303</link>
      <description>&lt;P&gt;Dear ballardw,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for this clever solution.&lt;BR /&gt;It works smoothly in the "real setting" with different number at a huge scale, too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is astonishing, which great kind of a help I do receive from this forum.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2016 09:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-counter-in-increments-of-i-by-subgroup/m-p/293969#M61303</guid>
      <dc:creator>Sinistrum</dc:creator>
      <dc:date>2016-08-25T09:28:33Z</dc:date>
    </item>
  </channel>
</rss>

