<?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: else if statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/else-if-statement/m-p/444262#M111190</link>
    <description>&lt;P&gt;You need to explain your logic.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why are you including FIRST.SITE_NUMBER if you only want to depend on STATUS?&lt;/P&gt;
&lt;P&gt;An example for 2 or 3 sites with multiple records each would help explain your problem better.&amp;nbsp; Post simple sample data in the form of a data step.&amp;nbsp; Post what you expect the result to be.&lt;/P&gt;</description>
    <pubDate>Fri, 09 Mar 2018 20:51:58 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-03-09T20:51:58Z</dc:date>
    <item>
      <title>else if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-if-statement/m-p/444260#M111188</link>
      <description>&lt;P&gt;&lt;BR /&gt;proc sort data=&amp;amp;Queries.2; BY STATUS Site_Number; RUN;&lt;BR /&gt;data &amp;amp;Queries.3;&lt;BR /&gt;set &amp;amp;Queries.2;&lt;BR /&gt;by status site_number;&lt;BR /&gt;if status="Open" and first.Site_Number then do; sitenum=0; end;&lt;BR /&gt;sitenum+1;&lt;BR /&gt;if status="Open" and last.Site_Number;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;I want to assign 0 for sitenum if status ne="Open"&lt;/P&gt;&lt;P&gt;I wasn't successful when I did it by else if statement&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please advise me for the best way to do it&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 20:39:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-if-statement/m-p/444260#M111188</guid>
      <dc:creator>mona4u</dc:creator>
      <dc:date>2018-03-09T20:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: else if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-if-statement/m-p/444261#M111189</link>
      <description>&lt;P&gt;&lt;SPAN&gt;if status="Open" and first.Site_Number then do; sitenum=0; end; &amp;lt;- This line will assign 0&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sitenum+1; if you don't have else here then it will change the value here&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Try this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=&amp;amp;Queries.2; 
BY STATUS Site_Number; 
RUN;
data &amp;amp;Queries.3;
retain sitenum;
set &amp;amp;Queries.2;
by status site_number;
if status="Open" and first.Site_Number then sitenum=0;
else sitenum+1;
if status="Open" and last.Site_Number;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Mar 2018 20:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-if-statement/m-p/444261#M111189</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-09T20:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: else if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-if-statement/m-p/444262#M111190</link>
      <description>&lt;P&gt;You need to explain your logic.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why are you including FIRST.SITE_NUMBER if you only want to depend on STATUS?&lt;/P&gt;
&lt;P&gt;An example for 2 or 3 sites with multiple records each would help explain your problem better.&amp;nbsp; Post simple sample data in the form of a data step.&amp;nbsp; Post what you expect the result to be.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 20:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-if-statement/m-p/444262#M111190</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-09T20:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: else if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-if-statement/m-p/444267#M111193</link>
      <description>&lt;P&gt;I need the compute the sitenum if status="Open"&amp;nbsp;&lt;/P&gt;&lt;P&gt;at the same time I need to assign 0 for sitenumb if status ne "Open"&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 21:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-if-statement/m-p/444267#M111193</guid>
      <dc:creator>mona4u</dc:creator>
      <dc:date>2018-03-09T21:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: else if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/else-if-statement/m-p/444270#M111195</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134228"&gt;@mona4u&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I need the compute the sitenum if status="Open"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;at the same time I need to assign 0 for sitenumb if status ne "Open"&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sounds like you need two variables.&amp;nbsp; One to "compute" and other that is what you actually want to output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;retain site_counter 0 ;
if status='OPEN' then do;
   site_counter+1;
   sitenum = site_counter;
end;
else sitenum=0;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Mar 2018 21:04:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/else-if-statement/m-p/444270#M111195</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-09T21:04:10Z</dc:date>
    </item>
  </channel>
</rss>

