<?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: Cannot run multiple %include statements within a macro function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963522#M375357</link>
    <description>&lt;P&gt;Anytime you get&lt;/P&gt;
&lt;PRE&gt;NOTE: The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation marks.&lt;/PRE&gt;
&lt;P&gt;you have to look for something unbalanced in the code. Unbalanced quotes, missing closing parentheses, %MACRO without a proper %MEND, and so on.&lt;/P&gt;
&lt;P&gt;Note that you do not need to create and execute a macro if you only have simple unnested %IF %THEN %DO. You can run those in "open code" and remove at least part of the complexity, particularly for testing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do your include files contain? If there are more macro definitions in there, they might be part if the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start wit a simplified version of the process (as already suggested) and expand from there until you get a problem; you will then have clear clue where to look.&lt;/P&gt;</description>
    <pubDate>Sat, 05 Apr 2025 08:01:25 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2025-04-05T08:01:25Z</dc:date>
    <item>
      <title>Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963506#M375350</link>
      <description>&lt;P&gt;Hi folks, I am losing my mind over something that I thought should be really straightforward. I've searched online for about 3 hours now and can't find any answers. I'm trying to create a macro function that uses some variable value from a prompt to run a set of other programs sequentially. I have tried a dozen or so variations, but the heart of my code comes down to this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro choose_progs(which_progs);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%if &amp;amp;which_progs = set1&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%include "mypath\folder1\program1.sas";&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%include "mypath\folder1\program2.sas";&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%else&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%if &amp;amp;which_progs = set2 or&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;which_progs = set3&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%include "mypath\folder2\program1.sas";&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* The program names are the same for both sets but the filepath is slightly different */&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%include "mypath\folder2\program2.sas";&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend choose_progs;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%choose_progs(set1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I run this, the first file in set1 runs fine but then ends with a final log entry "NOTE: Extraneous text on %END statement ignored." and the second file never even starts.&lt;/P&gt;&lt;P&gt;If I have the audacity to try and run again to test a change, I just get the following: "NOTE: The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation marks." There are definitely no unbalanced quotes, but my file paths are fairly long. All four of these programs will run fine on their own, I just for the life of me can't figure out how to automate this. I've also tried to use %include filePath("folder1\program1.sas", folder1\program2.sas"), but that doesn't work either. It still just runs the first program and stops.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do any of you know what I'm doing wrong here?&lt;/P&gt;</description>
      <pubDate>Sat, 05 Apr 2025 00:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963506#M375350</guid>
      <dc:creator>TheEsotericPunk</dc:creator>
      <dc:date>2025-04-05T00:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963509#M375352</link>
      <description>&lt;P&gt;My first guess is that it's something to do with what's in those %include programs.&amp;nbsp; Can you remove those temporarily and just replace with, e.g.,&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put loaded from folder1;


%put loaded from folder2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that works, then I suspect you need to look at the included programs.&amp;nbsp; The only other thing I can think of is that sometimes I've had weird issues with not having a semicolon directly after %MEND (though this is usually just on Linux).&amp;nbsp; You might try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* replacing this ;
%MEND choose_programs;

...with this:
%MEND; *choose_programs;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Apr 2025 00:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963509#M375352</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-05T00:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963510#M375353</link>
      <description>&lt;P&gt;Changing the semicolon to be right after %mend doesn't work. And I guess I don't understand how to use your other suggestion. I replaced the entire %include line with your %put line and it doesn't do anything.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Apr 2025 01:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963510#M375353</guid>
      <dc:creator>TheEsotericPunk</dc:creator>
      <dc:date>2025-04-05T01:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963511#M375354</link>
      <description>&lt;P&gt;I tested you code, and get no problem.&lt;/P&gt;
&lt;P&gt;Maybe you need these options to check what is going on your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro choose_progs(which_progs);

     %if &amp;amp;which_progs = set1

          %then %do;

               %include "c:\temp\z\a.sas";

               %include "c:\temp\z\b.sas";

          %end;

 

     %else

     %if &amp;amp;which_progs = set2 or 

            &amp;amp;which_progs = set3

          %then %do;

               %include "c:\temp\z\aa.sas";          /* The program names are the same for both sets but the filepath is slightly different */

               %include "c:\temp\z\bb.sas";

          %end;

%mend choose_progs;

 
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;option mprint mlogic symbolgen;&lt;/STRONG&gt;&lt;/FONT&gt;
%choose_progs(set2);&lt;/PRE&gt;
&lt;P&gt;Here is LOG:&lt;/P&gt;
&lt;PRE&gt;1    %macro choose_progs(which_progs);
2
3         %if &amp;amp;which_progs = set1
4
5              %then %do;
6
7                   %include "c:\temp\z\a.sas";
8
9                   %include "c:\temp\z\b.sas";
10
11             %end;
12
13
14
15        %else
16
17        %if &amp;amp;which_progs = set2 or
18
19               &amp;amp;which_progs = set3
20
21             %then %do;
22
23                  %include "c:\temp\z\aa.sas";          /* The program names are the same for both sets but the filepath is
23 ! slightly different */
24
25                  %include "c:\temp\z\bb.sas";
26
27             %end;
28
29   %mend choose_progs;
30
31
32   option mprint mlogic symbolgen;
33   %choose_progs(set2);
MLOGIC(CHOOSE_PROGS):  Beginning execution.
MLOGIC(CHOOSE_PROGS):  Parameter WHICH_PROGS has value set2
SYMBOLGEN:  Macro variable WHICH_PROGS resolves to set2
MLOGIC(CHOOSE_PROGS):  &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%IF condition &amp;amp;which_progs = set1 is FALSE&lt;/STRONG&gt;&lt;/FONT&gt;
SYMBOLGEN:  Macro variable WHICH_PROGS resolves to set2
SYMBOLGEN:  Macro variable WHICH_PROGS resolves to set2
MLOGIC(CHOOSE_PROGS):  &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;%IF condition &amp;amp;which_progs = set2 or              &amp;amp;which_progs = set3 is TRUE&lt;/STRONG&gt;&lt;/FONT&gt;
NOTE: Writing HTML Body file: sashtml.htm
MPRINT(CHOOSE_PROGS):   proc print data=sashelp.class(obs=1);
MPRINT(CHOOSE_PROGS):  run;

NOTE: There were 1 observations read from the data set SASHELP.CLASS.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.78 seconds
      cpu time            0.45 seconds


MPRINT(CHOOSE_PROGS):   proc print data=sashelp.heart(obs=1);
MPRINT(CHOOSE_PROGS):  run;

NOTE: There were 1 observations read from the data set SASHELP.HEART.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


MLOGIC(CHOOSE_PROGS):  Ending execution.











&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Apr 2025 02:04:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963511#M375354</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-04-05T02:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963515#M375355</link>
      <description>&lt;P&gt;What I mean is, if you comment out the include statements and replace with notes, do you see the notes in the log and does the program run without errors?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; .... %then %do;
          /*
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%include&amp;nbsp;/some/path1/prog1.sas;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%include&amp;nbsp;/some/path1/prog2.sas;&amp;nbsp;&amp;nbsp;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%put&amp;nbsp;**** path1&amp;nbsp;programs&amp;nbsp;for: &amp;amp;which_progs;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%else&amp;nbsp;%do;
          /*
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%include&amp;nbsp;/some/path2/prog1.sas;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%include&amp;nbsp;/some/path2/prog2.sas;&amp;nbsp;&amp;nbsp;*/
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%put&amp;nbsp;**** path2&amp;nbsp;programs&amp;nbsp;for: &amp;amp;which_progs;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%end;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So, the question is, does this program run without error?&amp;nbsp; Can you run it more than once?&amp;nbsp; If so, try uncommenting the %include statements one-by-one to see which one breaks it.&amp;nbsp; Ultimately, though, it might be hard to diagnose your problem without seeing what's going on in the programs you're including.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Apr 2025 02:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963515#M375355</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-05T02:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963522#M375357</link>
      <description>&lt;P&gt;Anytime you get&lt;/P&gt;
&lt;PRE&gt;NOTE: The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation marks.&lt;/PRE&gt;
&lt;P&gt;you have to look for something unbalanced in the code. Unbalanced quotes, missing closing parentheses, %MACRO without a proper %MEND, and so on.&lt;/P&gt;
&lt;P&gt;Note that you do not need to create and execute a macro if you only have simple unnested %IF %THEN %DO. You can run those in "open code" and remove at least part of the complexity, particularly for testing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do your include files contain? If there are more macro definitions in there, they might be part if the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start wit a simplified version of the process (as already suggested) and expand from there until you get a problem; you will then have clear clue where to look.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Apr 2025 08:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963522#M375357</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-04-05T08:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963530#M375358</link>
      <description>&lt;P&gt;Hey! &lt;CODE&gt;%include&lt;/CODE&gt; doesn’t work well inside a macro like that because it runs before the macro finishes. Try using &lt;CODE&gt;%include&lt;/CODE&gt; outside the macro or use &lt;CODE&gt;call execute()&lt;/CODE&gt; if you want to include files based on a condition. Hope this helps!&lt;/P&gt;</description>
      <pubDate>Sat, 05 Apr 2025 14:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963530#M375358</guid>
      <dc:creator>DataCruncherX</dc:creator>
      <dc:date>2025-04-05T14:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963533#M375359</link>
      <description>&lt;P&gt;Most likely the value passed in does not match either %IF condition so none of the include statements run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the only difference is the path just put the path into a macro variable.&amp;nbsp; Then you only need to code one set of %INCLUDE statements.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Apr 2025 15:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963533#M375359</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-05T15:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963573#M375371</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure what version of SAS you are using, but try checking your log for the below warning, once your&amp;nbsp;&lt;FONT face="courier new,courier"&gt;%include&lt;/FONT&gt; has been invoked:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WARNING: Truncated record.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This can indicate that a line of code has been truncated in the &lt;FONT face="courier new,courier"&gt;%include&lt;/FONT&gt; code (due to its line length), which in turn can exhibit the symptoms you have described. If you find the message in the log, then try referring to&amp;nbsp;&lt;A href="https://support.sas.com/kb/39/619.html" target="_blank"&gt;39619 - Options you can use on the %INCLUDE statement such as a LRECL= specification&lt;/A&gt;&amp;nbsp;to see if that helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Apr 2025 10:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963573#M375371</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2025-04-07T10:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963575#M375372</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;already demonstrated that the syntax as such is o.k. so it must be an issue with the code you're including.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get more info into the log for debugging, execute your macro with the following options:&lt;/P&gt;
&lt;PRE&gt;option mprint mlogic symbolgen source2; &lt;/PRE&gt;
&lt;P&gt;So something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option mprint mlogic symbolgen source2; 
%macro choose_progs(which_progs);
  %if &amp;amp;which_progs = set1 %then
    %do;
      %include "mypath\folder1\program1.sas";
      %include "mypath\folder1\program2.sas";
    %end;
  %else
  %if &amp;amp;which_progs = set2 or &amp;amp;which_progs = set3 %then 
    %do;
      %include "mypath\folder2\program1.sas";
      %include "mypath\folder2\program2.sas";
    %end;
%mend choose_progs;

%choose_progs(set1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happens if you run the selected %include statements outside of the macro?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;      %include "mypath\folder1\program1.sas" /source2;
      %include "mypath\folder1\program2.sas" /source2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Apr 2025 11:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963575#M375372</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2025-04-07T11:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963576#M375373</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;%include&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;doesn’t work well inside a macro like that because it runs before the macro finishes.&amp;nbsp;&lt;/SPAN&gt;" - please explain what do you mean by this sentence? Because in the form it is, it is false.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 07 Apr 2025 11:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963576#M375373</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-04-07T11:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963579#M375375</link>
      <description>&lt;P&gt;Doesn't your program file contain something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
file "R:\file_to_be_included.sas";
input;
put _infile_;
cards4;
proc print data=sashelp.iris(obs=1);
run;

%macro internal_macro();
%if 1=1 %then
%do;
  data test1;
    set sashelp.cars(obs=1);
  run;
%end                       /* &amp;lt;== missing semicolon !!!!!!!!! HERE */
%mend internal_macro;

data test2;
  set sashelp.class(obs=1);
run;
;;;;
run;



%macro choose_progs(which_progs);
     %if &amp;amp;which_progs = set1
          %then %do;
               %include "R:\file_to_be_included.sas" / source2;
     %end;
     %else
     %if &amp;amp;which_progs = set2 or 
         &amp;amp;which_progs = set3
          %then %do;
                    %put THE OTHER CASE!;
                %end;
%mend choose_progs;

 
%choose_progs(set1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 07 Apr 2025 12:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963579#M375375</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-04-07T12:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963779#M375413</link>
      <description>&lt;P&gt;When you say "&lt;SPAN&gt;If there are more macro definitions in there, they might be part of the problem", what do you mean by that? The files I am trying to add with %include do have other macros in them, however I have tested them all for months and they all run flawlessly on their own. All I am trying to do is wrap them all together into one process that chooses which set of files to run based on a user prompt. I have been trying to work with a simplified version of the process; the code I sent is only testing with two program files, but eventually there will be around 15 files per path. What's happening is this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1. I run the code and it correctly selects the filepath.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. It runs the first %include program just fine.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. The log shows "NOTE: %INCLUDE (level 1) ending."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4. It starts the second file with log: "NOTE: %INCLUDE (level 1) file mypath\folder1\program2.sas&amp;nbsp;is file mypath\folder1\program2.sas."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;5. The log shows all of the code from program2 but none of it runs.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;6. After a macro function within program2 is ended, the log generates "NOTE: Extraneous text on %END statement ignored." and then the code stops running and gives another&amp;nbsp;"NOTE: %INCLUDE (level 1) ending."&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;From my actual code log here is what that looks like:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1858 +%mend choose_data;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;This is the end of the macro within program2&lt;/FONT&gt;&lt;BR /&gt;NOTE: Extraneous text on %END statement ignored.&lt;BR /&gt;1859 +&lt;BR /&gt;1860 +/* Run population data creation */&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;FONT color="#FF0000"&gt;These are the lines that run the macro in program2&lt;/FONT&gt;&lt;BR /&gt;1861 +%choose_data(&amp;amp;use_data.);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;except they don't actually run.&lt;/FONT&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So, I think when you say that having macro definitions within this may be a problem, you might be on to something.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regarding the unbalanced note I get,&amp;nbsp;I have looked for anything unbalanced but can't find anything. As I said above, all the %include programs run with no warnings or errors, so they are all closed fine. Another user (Ksharp) mentioned that they tried my code and it worked fine, so I think it's balanced. This is one of the parts that's so maddening. When I open SAS EG I can run the code and just get the situation above (first program runs, second one doesn't). If I try to run a&amp;nbsp;&lt;EM&gt;second&lt;/EM&gt; time, that's when the unbalanced error comes up and then nothing runs at all. I have to completely close and restart SAS EG to try again.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 19:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963779#M375413</guid>
      <dc:creator>TheEsotericPunk</dc:creator>
      <dc:date>2025-04-08T19:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963780#M375414</link>
      <description>&lt;P&gt;I don't get that warning.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 19:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963780#M375414</guid>
      <dc:creator>TheEsotericPunk</dc:creator>
      <dc:date>2025-04-08T19:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963781#M375415</link>
      <description>&lt;P&gt;Exact same issues. But if I go to each of those two files and run them on their own, everything runs perfectly.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 19:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963781#M375415</guid>
      <dc:creator>TheEsotericPunk</dc:creator>
      <dc:date>2025-04-08T19:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963782#M375416</link>
      <description>&lt;P&gt;Are you just asking if the included files might be missing a semicolon or something? If so, then no, they are not. They run just fine on their own with no warnings or errors.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 19:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963782#M375416</guid>
      <dc:creator>TheEsotericPunk</dc:creator>
      <dc:date>2025-04-08T19:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963783#M375417</link>
      <description>&lt;P&gt;I should also add that the program1 file contains macros also, but those don't seem to cause any issues. It seems only the macro in program2 causes problems. But again, I can't understand why.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 19:50:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963783#M375417</guid>
      <dc:creator>TheEsotericPunk</dc:creator>
      <dc:date>2025-04-08T19:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963784#M375418</link>
      <description>&lt;P&gt;Here's what I would try:&lt;/P&gt;
&lt;P&gt;Create 4 new mini programs:&lt;/P&gt;
&lt;P&gt;\mypath\folder1\fake1.sas;&lt;/P&gt;
&lt;P&gt;\mypath\folder1\fake2.sas;&lt;/P&gt;
&lt;P&gt;\mypath\folder2\fake1.sas;&lt;/P&gt;
&lt;P&gt;\mypath\folder2\fake2.sas;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All 4 of these programs can just be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;** folder1\fake1.sas ;
data folder1_fake1;
x=1;
run;

** folder1\fake2.sas ;
data folder1_fake2;
x=1;
run;

** folder2\fake1.sas ;
data folder2_fake1;
x=1;
run;

** folder2\fake2.sas ;
data folder2_fake2;
x=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Literally save those as 4 distinct files.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace your 4 include statements so that they're instead pointing at the above, respectively.&lt;/P&gt;
&lt;P&gt;Make sure the program runs OK like this.&lt;/P&gt;
&lt;P&gt;If so, replace the first fake program with the first real one.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Retry.&lt;/P&gt;
&lt;P&gt;Repeat until it fails.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Btw, avoid commenting out % statements with * -- this can lead to weird things, i.e.,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;** instead of this: ;
*%include "some_program.sas";

** do one of these: ;
/* %include "some_program.sas"; */

* or, easier... ;
*include "some_program.sas";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 20:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963784#M375418</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-04-08T20:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963785#M375419</link>
      <description>&lt;P&gt;Remove the macro from your calling program.&amp;nbsp; It is not needed unless you are running some ancient version of SAS that does not support simple %IF/%THEN/%DO/%END blocks in open code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are running some ancient version then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check the line lengths of your included programs just to make sure that is not an issue.&amp;nbsp; A simple data step will tell you in the notes the maximum line length read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile 'myfile.sas' expandtabs;
  input;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure the programs do not have any data steps that use in-line data (or PARMCARDS statements) as those are not allowing inside of a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error message in your original message was about a missing semicolon following an %END statement.&amp;nbsp; Not a %MEND statement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also check your programs for any STATEMENT comments.&amp;nbsp; Those are comments that start with * and end with ;.&amp;nbsp; In open code you can have unbalanced quotes inside of statement comments, like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Don't use unbalanced quotes in statement comments ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you wrap that in a macro then the macro processor will treat * and Don as two tokens and then hunt for the closing quote and so "eat" the semi-colon.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 20:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963785#M375419</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-08T20:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot run multiple %include statements within a macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963791#M375420</link>
      <description>&lt;P&gt;OMG. I feel like a total idiot right now. It was a missing semi colon on one of the %end rows for part of the macro that was the unused part of the %IF. So I ran the code inside that and it runs fine but when I run the actual&amp;nbsp;&lt;EM&gt;macro&lt;/EM&gt; it fails.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 20:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-run-multiple-include-statements-within-a-macro-function/m-p/963791#M375420</guid>
      <dc:creator>TheEsotericPunk</dc:creator>
      <dc:date>2025-04-08T20:44:07Z</dc:date>
    </item>
  </channel>
</rss>

