<?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: if then do else if do in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803993#M316593</link>
    <description>&lt;P&gt;Against a gazillion of advice to the contrary, you still refuse to use proper code formatting with indentation, which makes finding such an issue a breeze. If you are not interested in advice, why do you come here at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start by using consistent indentation for your do/end blocks, and the problem will jump into your eyes so hard that I have to fear for your future eyesight.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2022 07:24:13 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-03-25T07:24:13Z</dc:date>
    <item>
      <title>if then do else if do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803985#M316590</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data even_odd;
do i= 1 to 100 ;
if mod(i,2)=0 then do;
number='Even' ;
end;

else if mod(i,2)=1 then do ;
number ='Odd';
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am using if then do else if do&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to get even and odd result in number variable column&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 06:37:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803985#M316590</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2022-03-25T06:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: if then do else if do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803989#M316591</link>
      <description>&lt;P&gt;And what is your question?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 06:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803989#M316591</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-25T06:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: if then do else if do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803991#M316592</link>
      <description>&lt;P&gt;Error unclosed Do block&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 07:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803991#M316592</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2022-03-25T07:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: if then do else if do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803993#M316593</link>
      <description>&lt;P&gt;Against a gazillion of advice to the contrary, you still refuse to use proper code formatting with indentation, which makes finding such an issue a breeze. If you are not interested in advice, why do you come here at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start by using consistent indentation for your do/end blocks, and the problem will jump into your eyes so hard that I have to fear for your future eyesight.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 07:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803993#M316593</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-25T07:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: if then do else if do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803995#M316594</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data even_odd;
do i= 1 to 100 ;
	if mod(i,2)=0 then do;
number='Even' ;output;
		end;

	else if mod(i,2)=1 then do ;
number ='Odd';output;
	end;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2022 07:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803995#M316594</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2022-03-25T07:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: if then do else if do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803997#M316595</link>
      <description>&lt;P&gt;Don't use tabs in code, use a consistent number of blanks. SAS Studio and Enterprise Guide provide options for replacing tabs with blanks while you type code, my "fictional" tab width is always set to 2, so my recommendation for &amp;nbsp;formatted code looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data even_odd;
do i = 1 to 100;
  if mod(i,2) = 0
  then do;
    number = 'Even';
    output;
  end;
  else do;
    number ='Odd';
    output;
  end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The second IF is not necessary as the MOD function with a second parameter of 2 can only return 0 or 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you can make your code even simpler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data even_odd;
length i 8 number $5;
do i = 1 to 100;
  number = ifc(mod(i,2),"Odd","Even");
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2022 07:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/803997#M316595</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-25T07:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: if then do else if do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/804064#M316610</link>
      <description>&lt;PRE&gt;data even_odd;
   do i= 1 to 100 ;
      if mod(i,2)=0 then do;
         number='Even' ;
      end;

      else if mod(i,2)=1 then do ;
         number ='Odd';
      end;

/* see anything missing*/
run;
&lt;/PRE&gt;
&lt;P&gt;Line up your code and things are easier to see exactly where the problem is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Error unclosed Do block" means that you have a DO without an END&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 14:10:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/804064#M316610</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-25T14:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: if then do else if do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/804180#M316646</link>
      <description>&lt;P&gt;One more way of "readable" indentation would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data even_odd;
  do i = 1 to 100;
    if mod(i,2) = 0 then 
      do;
        number = 'Even';
        output;
      end;
    else 
      do;
        number ='Odd';
        output;
      end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 20:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-do-else-if-do/m-p/804180#M316646</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-03-25T20:18:41Z</dc:date>
    </item>
  </channel>
</rss>

