<?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 count consecutive 1's for each id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-consecutive-1-s-for-each-id/m-p/776393#M246920</link>
    <description>&lt;P&gt;Perfect. So simple. Thank you.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Oct 2021 08:04:17 GMT</pubDate>
    <dc:creator>mgrasmussen</dc:creator>
    <dc:date>2021-10-26T08:04:17Z</dc:date>
    <item>
      <title>How to count consecutive 1's for each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-consecutive-1-s-for-each-id/m-p/776385#M246915</link>
      <description>&lt;P&gt;Dear SAS experts&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create a variable that&amp;nbsp;includes running numbers (1, 2 ..) of consecutive 1s according to a variabel (num), but I want to do this seperately for the values of each id. I.e. when the consecutive 1s cross two ids in the ordered dataset I would like running numbering to start over (as is the case in the variable want_var). The difference between the variable want_var and have_var can be seen below after running the code. Here, the 1s cross id 2 and 3, but using my code the numbering does not start over. Rather, it continues the count. Is there some simple way to&lt;SPAN style="font-family: inherit;"&gt;&amp;nbsp;modify my code such that I can get the variable that I am looking for?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id order num want_var;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 0 0&lt;BR /&gt;1 2 1 1&lt;BR /&gt;1 3 1 2&lt;BR /&gt;1 4 0 0&lt;BR /&gt;2 1 0 0&lt;BR /&gt;2 2 1 1&lt;BR /&gt;3 1 1 1&lt;BR /&gt;3 2 1 2&lt;BR /&gt;3 3 0 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;set have;&lt;BR /&gt;have_var+num;&lt;BR /&gt;if num=0 then have_var=0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 07:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-consecutive-1-s-for-each-id/m-p/776385#M246915</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2021-10-26T07:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to count consecutive 1's for each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-consecutive-1-s-for-each-id/m-p/776388#M246918</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by id;
if first.id or num = 0 then want_var = 0;
want_var + num;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Oct 2021 07:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-consecutive-1-s-for-each-id/m-p/776388#M246918</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-26T07:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to count consecutive 1's for each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-count-consecutive-1-s-for-each-id/m-p/776393#M246920</link>
      <description>&lt;P&gt;Perfect. So simple. Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 08:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-count-consecutive-1-s-for-each-id/m-p/776393#M246920</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2021-10-26T08:04:17Z</dc:date>
    </item>
  </channel>
</rss>

