<?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: Counts number of rows between two rows depending on criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counts-number-of-rows-between-two-rows-depending-on-criteria/m-p/802967#M316161</link>
    <description>&lt;P&gt;You want to:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Prior to checking the current practice, reset count to 0 if the preceding practice is optional.&lt;/LI&gt;
&lt;LI&gt;Increment count by 1 if the current practice is not optional.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have; 
  if lag(practice)='Optional' then count=0;
  count+(practice^='Optional');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;v&lt;/P&gt;</description>
    <pubDate>Sun, 20 Mar 2022 04:23:57 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-03-20T04:23:57Z</dc:date>
    <item>
      <title>Counts number of rows between two rows depending on criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counts-number-of-rows-between-two-rows-depending-on-criteria/m-p/802964#M316159</link>
      <description>&lt;P&gt;I'm trying to create a new column that counts the number of practice sessions between each optional practice session, but I want it to reset the counts between each two optional sessions and not aggregate. How can I do this? I know how to count it by aggregating the observations, but not how to reset them between each optional session.&lt;/P&gt;&lt;PRE&gt;data have;
  input ID $Practice;
 datalines;&lt;BR /&gt;1 Mandatory&lt;BR /&gt;2 Mandatory&lt;BR /&gt;3 Optional&lt;BR /&gt;4 Optional&lt;BR /&gt;5 Mandatory&lt;BR /&gt;6 Mandatory&lt;BR /&gt;7 Mandatory&lt;BR /&gt;8 Mandatory&lt;BR /&gt;9 Optional&lt;BR /&gt;10 Mandatory&lt;BR /&gt;11 Mandatory&lt;BR /&gt;12 Optional&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;I basically want a dataset that looks like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Practice&amp;nbsp; &amp;nbsp;Count&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 Mandatory&amp;nbsp; &amp;nbsp; 1&amp;nbsp;&lt;BR /&gt;2 Mandatory&amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;3 Optional&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;4 Optional&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;5 Mandatory&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;6 Mandatory&amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;7 Mandatory&amp;nbsp; &amp;nbsp; 3&amp;nbsp;&amp;nbsp;&lt;BR /&gt;8 Mandatory&amp;nbsp; &amp;nbsp; 4&lt;BR /&gt;9 Optional&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;BR /&gt;10 Mandatory&amp;nbsp; 1&lt;BR /&gt;11 Mandatory&amp;nbsp; &amp;nbsp;2&lt;BR /&gt;12 Optional&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2022 03:30:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counts-number-of-rows-between-two-rows-depending-on-criteria/m-p/802964#M316159</guid>
      <dc:creator>nharuka</dc:creator>
      <dc:date>2022-03-20T03:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Counts number of rows between two rows depending on criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counts-number-of-rows-between-two-rows-depending-on-criteria/m-p/802967#M316161</link>
      <description>&lt;P&gt;You want to:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Prior to checking the current practice, reset count to 0 if the preceding practice is optional.&lt;/LI&gt;
&lt;LI&gt;Increment count by 1 if the current practice is not optional.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have; 
  if lag(practice)='Optional' then count=0;
  count+(practice^='Optional');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;v&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2022 04:23:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counts-number-of-rows-between-two-rows-depending-on-criteria/m-p/802967#M316161</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-20T04:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: Counts number of rows between two rows depending on criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counts-number-of-rows-between-two-rows-depending-on-criteria/m-p/803002#M316184</link>
      <description>&lt;P&gt;Hi V,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code didn't work. When I tried to use it, it gave me "." for most of the mandatory cells and then "0" for the mandatory rows that comes right after the optional rows instead. I checked my log as well and there were no error messages so I'm not sure what went wrong.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2022 19:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counts-number-of-rows-between-two-rows-depending-on-criteria/m-p/803002#M316184</guid>
      <dc:creator>nharuka</dc:creator>
      <dc:date>2022-03-20T19:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Counts number of rows between two rows depending on criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counts-number-of-rows-between-two-rows-depending-on-criteria/m-p/803003#M316185</link>
      <description>&lt;P&gt;Please disregard this, it worked.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2022 19:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counts-number-of-rows-between-two-rows-depending-on-criteria/m-p/803003#M316185</guid>
      <dc:creator>nharuka</dc:creator>
      <dc:date>2022-03-20T19:10:36Z</dc:date>
    </item>
  </channel>
</rss>

