<?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: Resetting counter on condition in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49970#M13565</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data have;
input var1 $;
cards;
a
b
c
N
q
r
a
w
e
N
;
run;
data have;
 set have;
 if lag(var1) eq 'N' then count=0;
 count+1;
run;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 31 Mar 2012 03:11:42 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2012-03-31T03:11:42Z</dc:date>
    <item>
      <title>Resetting counter on condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49963#M13558</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What can I do to reset the counter on a given condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example Data;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Variable1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a&lt;/P&gt;&lt;P&gt;b&lt;/P&gt;&lt;P&gt;c&lt;/P&gt;&lt;P&gt;N&lt;/P&gt;&lt;P&gt;q&lt;/P&gt;&lt;P&gt;r&lt;/P&gt;&lt;P&gt;a&lt;/P&gt;&lt;P&gt;w&lt;/P&gt;&lt;P&gt;e&lt;/P&gt;&lt;P&gt;N&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;usually you would use _N_ to sequence but how do I get this output&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a 1&lt;/P&gt;&lt;P&gt;b 2&lt;/P&gt;&lt;P&gt;c 3&lt;/P&gt;&lt;P&gt;N 4&lt;/P&gt;&lt;P&gt;q 1&lt;/P&gt;&lt;P&gt;r&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;a 3&lt;/P&gt;&lt;P&gt;w 4&lt;/P&gt;&lt;P&gt;e 5&lt;/P&gt;&lt;P&gt;N 6&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I get it to reset. Maybe I do not understand what _N_ denotes properly. Please help. Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Akber.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 13:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49963#M13558</guid>
      <dc:creator>akberali67</dc:creator>
      <dc:date>2012-03-30T13:28:45Z</dc:date>
    </item>
    <item>
      <title>Resetting counter on condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49964#M13559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; how about:&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 12pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 12pt;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt; var1$;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 12pt;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;a&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;c&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;N&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;q&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;r&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;a&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;w&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;e&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;N&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 12pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt; temp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 12pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 12pt;"&gt;retain&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt; count;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 12pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt; lag(var1)=&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: purple; font-size: 12pt;"&gt;'N'&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 12pt;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt; count=&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 12pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 12pt;"&gt;else&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt; count+&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 12pt; background-color: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;STRONG style="color: navy; font-size: 12pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;STRONG style="color: navy; font-size: 12pt; background-color: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 12pt; background-color: white; font-family: 'Courier New';"&gt;print&lt;/STRONG&gt;;&lt;STRONG style="color: navy; font-size: 12pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 13:39:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49964#M13559</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-03-30T13:39:11Z</dc:date>
    </item>
    <item>
      <title>Resetting counter on condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49965#M13560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another method is to reset the counter on the record that marks the end of the group.&amp;nbsp; But do it AFTER writing the current count to the output dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; count+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if var1='N' then count=0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 13:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49965#M13560</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-03-30T13:43:52Z</dc:date>
    </item>
    <item>
      <title>Resetting counter on condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49966#M13561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another option is DOW,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;do count=1 by 1&amp;nbsp; until (var1='N');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 14:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49966#M13561</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-30T14:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Resetting counter on condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49967#M13562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... another way to reset the COUNT for each new group ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;data have;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;set have;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;count + (-(lag(var1) eq 'N')*count) + 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: courier new,courier;"&gt;run;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 16:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49967#M13562</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2012-03-30T16:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Resetting counter on condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49968#M13563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Hi Mike,&lt;/P&gt;&lt;P&gt;I will go to the BASUG Q1 meeting on 4/17/2012 in Boston. Looking forward to meeting you there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Linlin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 17:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49968#M13563</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-03-30T17:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Resetting counter on condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49969#M13564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This does work but it is very inefficient. It takes hours to run on even a small dataset. Probably because it assigns the values manually.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 19:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49969#M13564</guid>
      <dc:creator>akberali67</dc:creator>
      <dc:date>2012-03-30T19:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Resetting counter on condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49970#M13565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data have;
input var1 $;
cards;
a
b
c
N
q
r
a
w
e
N
;
run;
data have;
 set have;
 if lag(var1) eq 'N' then count=0;
 count+1;
run;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 Mar 2012 03:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Resetting-counter-on-condition/m-p/49970#M13565</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-03-31T03:11:42Z</dc:date>
    </item>
  </channel>
</rss>

