<?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: Count with multiple conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-with-multiple-conditions/m-p/667378#M199837</link>
    <description>You are a real saviour. Thank you so much.</description>
    <pubDate>Tue, 07 Jul 2020 08:20:33 GMT</pubDate>
    <dc:creator>Myurathan</dc:creator>
    <dc:date>2020-07-07T08:20:33Z</dc:date>
    <item>
      <title>Count with multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-with-multiple-conditions/m-p/667373#M199831</link>
      <description>&lt;P&gt;Dear SAS community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having trouble counting and resetting the count with conditions and your help would be much appreciated.&lt;/P&gt;&lt;P&gt;Suppose that I have data below; Count is the variable I am after.&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Flag&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Count&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&g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&lt;SPAN&gt;How can I achieve this? Please help. Thank you!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Myu&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 08:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-with-multiple-conditions/m-p/667373#M199831</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2020-07-07T08:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Count with multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-with-multiple-conditions/m-p/667375#M199834</link>
      <description>&lt;P&gt;What have you tried? Can you post the code? If not: please post the data in usable form.&lt;/P&gt;
&lt;P&gt;Untested:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	by ID;
	
	retain count;
	
	if first.ID then count = 0;
	
	if Flag = 1 then Count = Count + 1;
	else Count = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jul 2020 08:12:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-with-multiple-conditions/m-p/667375#M199834</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-07-07T08:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: Count with multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-with-multiple-conditions/m-p/667376#M199835</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Flag;
datalines;
A 0
A 0
A 1
A 1
A 0
A 1
A 1
B 1
B 1
B 0
B 1
B 1
;

data want;
    set have;
    by ID;
    if first.ID | flag=0 then Count=0;
    if flag then Count+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jul 2020 08:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-with-multiple-conditions/m-p/667376#M199835</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-07-07T08:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Count with multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-with-multiple-conditions/m-p/667378#M199837</link>
      <description>You are a real saviour. Thank you so much.</description>
      <pubDate>Tue, 07 Jul 2020 08:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-with-multiple-conditions/m-p/667378#M199837</guid>
      <dc:creator>Myurathan</dc:creator>
      <dc:date>2020-07-07T08:20:33Z</dc:date>
    </item>
  </channel>
</rss>

