<?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: How to apply a counter with limits for specific groups? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580293#M164821</link>
    <description>&lt;P&gt;So why not post a sample of the HAVE's&lt;/P&gt;
&lt;P&gt;1. your table&lt;/P&gt;
&lt;P&gt;2. The look tables with groups and associated limits&lt;/P&gt;
&lt;P&gt;3. Of course the expected output&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Aug 2019 22:43:57 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-08-09T22:43:57Z</dc:date>
    <item>
      <title>How to apply a counter with limits for specific groups?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580289#M164817</link>
      <description>&lt;P&gt;In the example below, group x has a counter limit of 3 and group y has a counter limit of 5. In each group, the counter starts when the MW value goes from &amp;gt;0 to 0.&amp;nbsp; Any ideas on how to code this?&amp;nbsp; In the real application of this, I have multiple "groups" all with different "counter" limits.&amp;nbsp; Any help is much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example dataset and the result I am trying to return:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="counter.PNG" style="width: 224px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31652iFC120CA452132DEB/image-size/large?v=v2&amp;amp;px=999" role="button" title="counter.PNG" alt="counter.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 22:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580289#M164817</guid>
      <dc:creator>Chad_OSU</dc:creator>
      <dc:date>2019-08-09T22:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a counter with limits for specific groups?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580290#M164818</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/284699"&gt;@Chad_OSU&lt;/a&gt;&amp;nbsp; &amp;nbsp;Do you have a look up table that has limits for each group. Also, my understanding is that counter values start for the set of zeros that follows the first non zero value, is this accurate?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 22:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580290#M164818</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-09T22:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a counter with limits for specific groups?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580292#M164820</link>
      <description>In application, yes I would have a look up table with the limits. And yes you are correct on when the counter starts.</description>
      <pubDate>Fri, 09 Aug 2019 22:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580292#M164820</guid>
      <dc:creator>Chad_OSU</dc:creator>
      <dc:date>2019-08-09T22:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a counter with limits for specific groups?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580293#M164821</link>
      <description>&lt;P&gt;So why not post a sample of the HAVE's&lt;/P&gt;
&lt;P&gt;1. your table&lt;/P&gt;
&lt;P&gt;2. The look tables with groups and associated limits&lt;/P&gt;
&lt;P&gt;3. Of course the expected output&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 22:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580293#M164821</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-09T22:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a counter with limits for specific groups?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580297#M164824</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data limits;
input group$ limit;
datalines;
x 3
y 5
run;

data have;
input group$ MW;
datalines;
x 0
x 0
x 5
x 5
x 0
x 0
x 0
x 0
x 0
x 0
x 0
y 0
y 0
y 5
y 0
y 0
y 0
y 0
y 0
y 0
y 0
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Expected output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="counter.PNG" style="width: 224px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31653iD267EE2428403890/image-size/large?v=v2&amp;amp;px=999" role="button" title="counter.PNG" alt="counter.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 22:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580297#M164824</guid>
      <dc:creator>Chad_OSU</dc:creator>
      <dc:date>2019-08-09T22:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a counter with limits for specific groups?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580307#M164828</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/284699"&gt;@Chad_OSU&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 limits;
input group$ limit;
datalines;
x 3
y 5
;
run;

data have;
input group$ MW;
datalines;
x 0
x 0
x 5
x 5
x 0
x 0
x 0
x 0
x 0
x 0
x 0
y 0
y 0
y 5
y 0
y 0
y 0
y 0
y 0
y 0
y 0
run;

data want;
do until(last.group);
 merge have limits;
 by group;
 if _f then _c=sum(_c,mw=0);
 counter=_c;
 if mw then _f=1;
 if mw or  _c&amp;gt;limit then counter=.;
 output;
end;
drop _:;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Aug 2019 23:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580307#M164828</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-09T23:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a counter with limits for specific groups?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580311#M164830</link>
      <description>&lt;P&gt;Thank you very much for the response.&amp;nbsp; This functions correctly with the given dataset.&amp;nbsp; Although, if the first x value is changed to 5, this is the output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture11.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31657iB2891E8FF1913A1B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture11.PNG" alt="Capture11.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would be looking for the counter to restart at line 5.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 23:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580311#M164830</guid>
      <dc:creator>Chad_OSU</dc:creator>
      <dc:date>2019-08-09T23:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a counter with limits for specific groups?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580312#M164831</link>
      <description>&lt;P&gt;Sorry&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/284699"&gt;@Chad_OSU&lt;/a&gt;&amp;nbsp; &amp;nbsp;Do you mean this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.group);
 merge have limits;
 by group;
 if mw then do; _f=1; _c=.;end;
 if _f then _c=sum(_c,mw=0);
 counter=_c;
 if mw or  _c&amp;gt;limit then counter=.;
 output;
end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Aug 2019 23:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580312#M164831</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-09T23:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply a counter with limits for specific groups?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580313#M164832</link>
      <description>Yes, that worked! Thank you very much!!</description>
      <pubDate>Fri, 09 Aug 2019 23:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-a-counter-with-limits-for-specific-groups/m-p/580313#M164832</guid>
      <dc:creator>Chad_OSU</dc:creator>
      <dc:date>2019-08-09T23:57:27Z</dc:date>
    </item>
  </channel>
</rss>

