<?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: macros %else %if... %then %do generated error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/976333#M378303</link>
    <description>&lt;P&gt;Remove the nesting.&amp;nbsp; Just use three independent %IF blocks.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let current_month_num = %sysfunc(month(%sysfunc(today())));

%if (&amp;amp;current_month_num=1 or &amp;amp;current_month_num=2 ) %then %do;
%put no report will be generated;
%end;

%if (&amp;amp;current_month_num=9 or &amp;amp;current_month_num=8 or &amp;amp;current_month_num=7) %then %do;
%put quarter to date comparison report;
%end;

%if (&amp;amp;current_month_num=3
  or &amp;amp;current_month_num=4
  or &amp;amp;current_month_num=5
  or &amp;amp;current_month_num=6
  or &amp;amp;current_month_num=10
  or &amp;amp;current_month_num=11
  or &amp;amp;current_month_num=12
) %do;
%put not in Q3 and not in Jan or Feb;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 03 Oct 2025 14:47:44 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-10-03T14:47:44Z</dc:date>
    <item>
      <title>macros %else %if... %then %do generated error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/976324#M378299</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following codes has generated an error message "Nesting of %IF statements in open code is not supported. %IF ignored.&amp;nbsp;Skipping to next %END statement."&amp;nbsp; &amp;nbsp;But if I deleted the red part of the codes (i.e., the 3 lines of codes starting from %else %if&amp;nbsp; ... %then %do)&amp;nbsp; , then the codes worked fine and generated the correct answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also changed part of the problematic codes to&amp;nbsp;(&amp;amp;current_month_num=9 or &amp;amp;current_month_num=10), and then changed it to (&amp;amp;current_month_num=10).&amp;nbsp;None of them work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please point out my mistake, and suggest a workaround solution?&amp;nbsp; Any help or any comments is highly appreciated.&amp;nbsp; Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let current_month_num = %sysfunc(month(%sysfunc(today())));&lt;BR /&gt;%if (&amp;amp;current_month_num=1 or &amp;amp;current_month_num=2 ) %then %do;&lt;BR /&gt;%put no report will be generated;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;%else %if (&amp;amp;current_month_num=9 or &amp;amp;current_month_num=8 or &amp;amp;current_month_num=7) %then %do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;%put quarter to date comparison report;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;%end;&lt;/FONT&gt;&lt;BR /&gt;%else %do;&lt;BR /&gt;%put not in Q3 and not in Jan or Feb;&lt;BR /&gt;%end;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2025 13:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/976324#M378299</guid>
      <dc:creator>ssll</dc:creator>
      <dc:date>2025-10-03T13:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: macros %else %if... %then %do generated error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/976327#M378301</link>
      <description>&lt;PRE&gt;Nesting of %IF statements in open code is not supported&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nested %IF is not supported in open code. The code in red is a nested %IF, in other words an %IF within another %IF. You cannot code this way outside of a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code seems like it should run inside a macro.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2025 14:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/976327#M378301</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-10-03T14:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: macros %else %if... %then %do generated error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/976333#M378303</link>
      <description>&lt;P&gt;Remove the nesting.&amp;nbsp; Just use three independent %IF blocks.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let current_month_num = %sysfunc(month(%sysfunc(today())));

%if (&amp;amp;current_month_num=1 or &amp;amp;current_month_num=2 ) %then %do;
%put no report will be generated;
%end;

%if (&amp;amp;current_month_num=9 or &amp;amp;current_month_num=8 or &amp;amp;current_month_num=7) %then %do;
%put quarter to date comparison report;
%end;

%if (&amp;amp;current_month_num=3
  or &amp;amp;current_month_num=4
  or &amp;amp;current_month_num=5
  or &amp;amp;current_month_num=6
  or &amp;amp;current_month_num=10
  or &amp;amp;current_month_num=11
  or &amp;amp;current_month_num=12
) %do;
%put not in Q3 and not in Jan or Feb;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Oct 2025 14:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/976333#M378303</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-10-03T14:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: macros %else %if... %then %do generated error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/976335#M378304</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/478402"&gt;@ssll&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could avoid the %IF-%THEN/%ELSE statements like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let m=NNEEEERRREEE;
%let N=no report will be generated;
%let R=quarter to date comparison report;
%let E=not in Q3 and not in Jan or Feb;

%let c=%substr(&amp;amp;m,&amp;amp;current_month_num,1);
%put &amp;amp;&amp;amp;&amp;amp;c;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I suspect that you actually want to execute some reporting statements if &lt;FONT face="courier new,courier"&gt;&amp;amp;c=R&lt;/FONT&gt;. In this case you could at least avoid the nesting:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let m=NNEEEERRREEE;
%let N=no report will be generated;
%let E=not in Q3 and not in Jan or Feb;

%let c=%substr(&amp;amp;m,&amp;amp;current_month_num,1);
%if &amp;amp;c=R %then %do;
  %inc 'C:\Temp\myQtoDreport.sas' / source;
%end;
%else %do;
  %put &amp;amp;&amp;amp;&amp;amp;c;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Oct 2025 15:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/976335#M378304</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-10-03T15:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: macros %else %if... %then %do generated error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/977606#M378516</link>
      <description>&lt;P&gt;Hi PaigeMiller, you are right, I have tested putting those codes inside a macro, and it worked and generated the correct output.&amp;nbsp; Sorry for my late reply and thank you so much for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Oct 2025 16:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/977606#M378516</guid>
      <dc:creator>ssll</dc:creator>
      <dc:date>2025-10-22T16:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: macros %else %if... %then %do generated error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/977607#M378517</link>
      <description>&lt;P&gt;Hi Tom, sorry for my late reply and thank you so much for&amp;nbsp; your reply. Yes I agree with you, using 3 independent %if blocks is a workaround solution cuz I just tested using 3 independent if blocks.&amp;nbsp; Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Oct 2025 16:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macros-else-if-then-do-generated-error/m-p/977607#M378517</guid>
      <dc:creator>ssll</dc:creator>
      <dc:date>2025-10-22T16:45:51Z</dc:date>
    </item>
  </channel>
</rss>

