<?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: Creating a counter variable with mutiple conditional statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-counter-variable-with-mutiple-conditional-statements/m-p/610742#M177911</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by id;
    if first.id then counter=1;
    prev_days=lag(days);
    if days&amp;gt;120 and prev_day&amp;gt;60 then counter=1; /* This condition still doesn't make sense to me */
    else if days&amp;gt;=0 and days&amp;lt;=120 and prev_day&amp;gt;120 then counter+1;
    else if days&amp;lt;0 then counter+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 10 Dec 2019 14:53:00 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-12-10T14:53:00Z</dc:date>
    <item>
      <title>Creating a counter variable with mutiple conditional statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-counter-variable-with-mutiple-conditional-statements/m-p/610725#M177899</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I'm trying to create a counter variable with multiple conditions. Please see below: the table includes the data in days and the counter I'm trying to program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; This is all within a subject.&amp;nbsp; If first subject then start counter = 1.&lt;/P&gt;&lt;P&gt;2. if Days&amp;nbsp; &amp;gt;120 and the lag of the previous Day &amp;gt; 60 then counter =1 if this is the&amp;nbsp;first observation meeting this criteria,&lt;/P&gt;&lt;P&gt;3. If Days &amp;gt;120&amp;nbsp;and lag of previous Day is &amp;lt;60 then don't add to the counter, rather this observation gets the same as the previous counter number.&lt;/P&gt;&lt;P&gt;4.&amp;nbsp;If Days&amp;nbsp;greater than 0 and&amp;nbsp;LE&amp;nbsp;120 then +1 to the counter and all other observations &amp;lt;120 are the same&amp;nbsp;counter value.&lt;/P&gt;&lt;P&gt;5. If Days is &amp;lt;0 then counter+1 for each instance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any and all assistance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Days&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Counter&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2514&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;141&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;99&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;54&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;0&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;-205&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;-290&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;5&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 10 Dec 2019 13:17:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-counter-variable-with-mutiple-conditional-statements/m-p/610725#M177899</guid>
      <dc:creator>Kimbraun1</dc:creator>
      <dc:date>2019-12-10T13:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a counter variable with mutiple conditional statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-counter-variable-with-mutiple-conditional-statements/m-p/610728#M177900</link>
      <description>&lt;P&gt;Your rules are incomplete. If days &amp;gt; 120 and previous day = 60 exactly, you don't say what should happen. If days is exactly equal to zero, you don't say what should happen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, your rules 1 and 2 seem to indicate that the counter starts at 1, then it can change, and then go back to 1 if rule 2 is satisfied, is this correct?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 13:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-counter-variable-with-mutiple-conditional-statements/m-p/610728#M177900</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-10T13:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a counter variable with mutiple conditional statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-counter-variable-with-mutiple-conditional-statements/m-p/610730#M177902</link>
      <description>&lt;P&gt;Hi Paige,&lt;/P&gt;&lt;P&gt;Thanks for your reply.&amp;nbsp; The 60 should be &amp;lt;= 60 and &amp;gt;= 0.&amp;nbsp; Yes, the counter starts at 1 each time, but will advance sequentially and not reset at 1 at any point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I so appreciate your help and responsiveness.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 13:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-counter-variable-with-mutiple-conditional-statements/m-p/610730#M177902</guid>
      <dc:creator>Kimbraun1</dc:creator>
      <dc:date>2019-12-10T13:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a counter variable with mutiple conditional statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-counter-variable-with-mutiple-conditional-statements/m-p/610742#M177911</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by id;
    if first.id then counter=1;
    prev_days=lag(days);
    if days&amp;gt;120 and prev_day&amp;gt;60 then counter=1; /* This condition still doesn't make sense to me */
    else if days&amp;gt;=0 and days&amp;lt;=120 and prev_day&amp;gt;120 then counter+1;
    else if days&amp;lt;0 then counter+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Dec 2019 14:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-counter-variable-with-mutiple-conditional-statements/m-p/610742#M177911</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-10T14:53:00Z</dc:date>
    </item>
  </channel>
</rss>

