<?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 %end %else do in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-end-else-do/m-p/958059#M373948</link>
    <description>&lt;P&gt;This line is a problem.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%don't create table;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hopefully that is not in your actual code because it could cause your macro to emit unbalance single quotes which will "eat" a lot of code until it finds a closing quote.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can test both A and B.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if (&amp;amp;A=0) or (&amp;amp;B=0) %then %do;
  * code to create table ;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps test B and C?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if (&amp;amp;B=0) or (&amp;amp;B=-&amp;amp;C) %then %do;
  * code to create table ;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if A or B might not be integers (1.5 for instance) then use %SYSEVALF().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysevalf( (&amp;amp;A=0) or (&amp;amp;B=0) ) %then %do;
  * code to create table ;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 03 Feb 2025 16:54:51 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-02-03T16:54:51Z</dc:date>
    <item>
      <title>%If %then do %end %else do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-end-else-do/m-p/958034#M373942</link>
      <description>&lt;P&gt;%MACRO validate;&lt;BR /&gt;%if &amp;amp;A = 0 %then %do;&amp;nbsp;&lt;BR /&gt;%createtable;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&amp;nbsp;&lt;BR /&gt;%if &amp;amp;B = 0 %then %do;&amp;nbsp;&lt;BR /&gt;%createtable;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&amp;nbsp;&lt;BR /&gt;%don't create table;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%Mend validate;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this code work?&lt;/P&gt;
&lt;P&gt;%if &amp;amp;A = 0 then&amp;nbsp;&amp;amp;B = 0, so always create table&lt;/P&gt;
&lt;P&gt;But it&amp;nbsp;%if &amp;amp;A &amp;lt;&amp;gt; 0,&amp;nbsp;&amp;amp;B can be 0 (and we want it to create table) or it can be &amp;lt;&amp;gt; 0 and we don't want it to create table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because&amp;nbsp;&amp;amp;A =&amp;nbsp;&amp;amp;B +&amp;nbsp;&amp;amp;C&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am I missing any %end or %else do?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2025 15:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-do-end-else-do/m-p/958034#M373942</guid>
      <dc:creator>InêsMaximiano</dc:creator>
      <dc:date>2025-02-03T15:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: %If %then do %end %else do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-end-else-do/m-p/958039#M373943</link>
      <description>&lt;P&gt;It seems to me the problem was overcomplicated. If &amp;amp;A= &amp;amp;B+&amp;amp;C and you need the table only when &amp;amp;A=0, then there is no need for &amp;amp;B= condition.&amp;nbsp;&lt;BR /&gt;I would simplify it like:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO validate;
	%if &amp;amp;A = 0 %then %do; 
		%createtable;
	%end;
	%else %do;
		%put NOTE: Condition is not true, table is not created; 
		%return;
	%end;
%Mend validate;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2025 15:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-do-end-else-do/m-p/958039#M373943</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2025-02-03T15:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: %If %then do %end %else do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-end-else-do/m-p/958043#M373946</link>
      <description>&lt;P&gt;Definitely a problem.&amp;nbsp; While unbalanced single quotes can create problems, this is a call to the macro DON&lt;/P&gt;
&lt;P&gt;%don&lt;/P&gt;
&lt;P&gt;The simplest version of this macro might be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if &amp;amp;A=0 or &amp;amp;B=0 %then %createtable;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Feb 2025 16:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-do-end-else-do/m-p/958043#M373946</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2025-02-03T16:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: %If %then do %end %else do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-end-else-do/m-p/958059#M373948</link>
      <description>&lt;P&gt;This line is a problem.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%don't create table;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hopefully that is not in your actual code because it could cause your macro to emit unbalance single quotes which will "eat" a lot of code until it finds a closing quote.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can test both A and B.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if (&amp;amp;A=0) or (&amp;amp;B=0) %then %do;
  * code to create table ;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps test B and C?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if (&amp;amp;B=0) or (&amp;amp;B=-&amp;amp;C) %then %do;
  * code to create table ;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if A or B might not be integers (1.5 for instance) then use %SYSEVALF().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysevalf( (&amp;amp;A=0) or (&amp;amp;B=0) ) %then %do;
  * code to create table ;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Feb 2025 16:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-do-end-else-do/m-p/958059#M373948</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-03T16:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: %If %then do %end %else do</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-do-end-else-do/m-p/958073#M373955</link>
      <description>&lt;P&gt;This code can't work because&lt;/P&gt;
&lt;PRE&gt;don't&lt;/PRE&gt;
&lt;P&gt;is not a valid name for a macro. Only letters, digits and underscores can be part of a macro name.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2025 17:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-do-end-else-do/m-p/958073#M373955</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-02-03T17:34:44Z</dc:date>
    </item>
  </channel>
</rss>

