<?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: Counting with conditions in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Counting-with-conditions/m-p/555521#M9693</link>
    <description>&lt;P&gt;Here's one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by subject;
if first.subject then newvar=0;
if condition = 1 then newvar = 1;
else if condition = 2 then do;
   if newvar then newvar + 1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The&amp;nbsp; condition "if newvar" will be false when NEWVAR is 0, true when it is some other integer.&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2019 02:06:48 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-05-02T02:06:48Z</dc:date>
    <item>
      <title>Counting with conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-with-conditions/m-p/555516#M9692</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;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Subject / Year / Condition&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A 1991 2&lt;/P&gt;&lt;P&gt;A 1992 2&lt;/P&gt;&lt;P&gt;A 1993 1&lt;/P&gt;&lt;P&gt;A 1994 2&lt;/P&gt;&lt;P&gt;A 1995 2&lt;/P&gt;&lt;P&gt;B 1990 1&lt;/P&gt;&lt;P&gt;B 1991 2&lt;/P&gt;&lt;P&gt;B 1992 1&lt;/P&gt;&lt;P&gt;B 1993 2&lt;/P&gt;&lt;P&gt;C 1991 2&lt;/P&gt;&lt;P&gt;C 1992 2&lt;/P&gt;&lt;P&gt;C 1993 2&lt;/P&gt;&lt;P&gt;C 1994 2&lt;/P&gt;&lt;P&gt;C 1995 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot change the order of this, and I would like to start counting&lt;/P&gt;&lt;P&gt;when first "1" appears and continue counting through "2" and reset each time "1" appears for the same individual.&lt;/P&gt;&lt;P&gt;so that it would give me:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A 1991 2 0&lt;/P&gt;&lt;P&gt;A 1992 2 0&lt;/P&gt;&lt;P&gt;A 1993 1 1&lt;/P&gt;&lt;P&gt;A 1994 2 2&lt;/P&gt;&lt;P&gt;A 1995 2 3&lt;/P&gt;&lt;P&gt;B 1990 1 1&lt;/P&gt;&lt;P&gt;B 1991 2 2&lt;/P&gt;&lt;P&gt;B 1992 1 1&lt;/P&gt;&lt;P&gt;B 1993 2 2&lt;/P&gt;&lt;P&gt;C 1991 2 0&lt;/P&gt;&lt;P&gt;C 1992 2 0&lt;/P&gt;&lt;P&gt;C 1993 2 0&lt;/P&gt;&lt;P&gt;C 1994 2 0&lt;/P&gt;&lt;P&gt;C 1995 1 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I achieve this? Please help. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;T&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 01:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-with-conditions/m-p/555516#M9692</guid>
      <dc:creator>tonoplast</dc:creator>
      <dc:date>2019-05-02T01:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Counting with conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-with-conditions/m-p/555521#M9693</link>
      <description>&lt;P&gt;Here's one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by subject;
if first.subject then newvar=0;
if condition = 1 then newvar = 1;
else if condition = 2 then do;
   if newvar then newvar + 1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The&amp;nbsp; condition "if newvar" will be false when NEWVAR is 0, true when it is some other integer.&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 02:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-with-conditions/m-p/555521#M9693</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-02T02:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: Counting with conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-with-conditions/m-p/555522#M9694</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Subject $ Year  Condition	;
cards;
A 1991 2
A 1992 2
A 1993 1
A 1994 2
A 1995 2
B 1990 1
B 1991 2
B 1992 1
B 1993 2
C 1991 2
C 1992 2
C 1993 2
C 1994 2
C 1995 1
;

data want;
set have;
by subject;
if first.subject then want=0;
if condition=1 then want=1;
else if want then want+1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 May 2019 02:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-with-conditions/m-p/555522#M9694</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-02T02:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: Counting with conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-with-conditions/m-p/555523#M9695</link>
      <description>&lt;P&gt;Thank you!! This works perfectly!&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 02:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-with-conditions/m-p/555523#M9695</guid>
      <dc:creator>tonoplast</dc:creator>
      <dc:date>2019-05-02T02:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Counting with conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-with-conditions/m-p/555524#M9696</link>
      <description>&lt;P&gt;And this too! Thank you very much!&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 02:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-with-conditions/m-p/555524#M9696</guid>
      <dc:creator>tonoplast</dc:creator>
      <dc:date>2019-05-02T02:16:31Z</dc:date>
    </item>
  </channel>
</rss>

