<?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: Conditional %INCLUDE Statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91014#M19251</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp; I'm having a hard time envisioning WHAT your "red" or "blue" files actually contain. At first, it sounded like they contained program code, because you said that they contained code. But now, in your more recent explanation, you said that the external files "contain several numerical variables hard-coded to certain values" -- that doesn't sound like code, that sounds like data. And, you further explained that the external files "are updated elsewhere so you cannot change this format" -- again ,that sounds like DATA, not CODE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; So, now, the problem sounds different than it did initially. Can you post an example of what is in the first file with the "red" or "blue" and example of the code or data in the 2 external files? I really feel like a concrete sample of your data would help and would eliminate the guessing about what you have and what you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; When you say that you want to "include the one set if colour is blue" and "the other if red" almost sounds to me like you want to go read a different external file based on some other variable value in the first file. Again, unless the two external files have "datalines" embedded in the program code, I am not sure now that the %include method is the right method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; The rule of thumb, when trying to code a macro solution to anything is to start with a working SAS program without any macro references.&amp;nbsp; So, do you have PROGRAM1.SAS and PROGRAM2.SAS to "include" or do you have DATA1.TXT and DATA2.TXT that you want to read conditionally? Can you show examples of the "real" code that you have and what is in your 3 files? That would be a big help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 31 Mar 2013 18:16:23 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2013-03-31T18:16:23Z</dc:date>
    <item>
      <title>Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91002#M19239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have two external files - both containing SAS code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both files contain the same variables so I do not want to include both files in all cases&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to use a %INCLUDE to pull in either of these based on the value of a variable in open code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i.e. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If colour = blue then %INCLUDE "Filepath/FileA"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If colour = red then %INCLUDE "Filepath/FileB"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a relatively straightforward way to accomplish this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 19:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91002#M19239</guid>
      <dc:creator>jjjames</dc:creator>
      <dc:date>2013-03-27T19:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91003#M19240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%let colour=blue;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;if "&amp;amp;colour"="blue" then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput('fname','FilePath/FileA');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;else do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symput('fname','FilePath/FileB');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%include "&amp;amp;fname";&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 20:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91003#M19240</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-03-27T20:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91004#M19241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From the manual:&lt;/P&gt;&lt;P&gt;Because %INCLUDE is a global statement and global statements are not executable, the %INCLUDE statement cannot be used in conditional logic&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 20:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91004#M19241</guid>
      <dc:creator>SteveNZ</dc:creator>
      <dc:date>2013-03-27T20:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91005#M19242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Seems like you would need a macro, and then conditionally issue one %include statement or the other one based on the colour.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternatively, if you don't want to do macros, you could use the LINK statement to branch to the code in FileA or FileB, but that code would have to be included in the datastep somehow.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if colour='blue' then Link FileA;&lt;/P&gt;&lt;P&gt;else if colour='red' then Link FileB;&lt;/P&gt;&lt;P&gt;return;&lt;/P&gt;&lt;P&gt;FileA:&lt;/P&gt;&lt;P&gt;/* File A code goes here */&lt;/P&gt;&lt;P&gt;return;&lt;/P&gt;&lt;P&gt;FileB:&lt;/P&gt;&lt;P&gt;/* File B code goes here */&lt;/P&gt;&lt;P&gt;return;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't forget your semi-colons&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 20:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91005#M19242</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-03-27T20:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91006#M19243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Thanks for your reply, so it would look something like this:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if colour='blue' then Link FileA;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;else if colour='red' then Link FileB;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;return;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;FileA:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%include "filepath/fileA";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;return;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;FileB:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%include "filepath/fileB";&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;return;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I originally tried to do something with macros, but both %include statements seemed to run regardless of the colour:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%macro macroA;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%include "filepath/fileA";&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%macro macroB;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%include "filepath/fileB";&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if colour='blue' then call execute ("macroA");&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;else if colour='red' &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;then call execute ("macroB");&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 20:23:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91006#M19243</guid>
      <dc:creator>jjjames</dc:creator>
      <dc:date>2013-03-27T20:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91007#M19244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;FileA:&lt;/P&gt;
&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;%include "filepath/fileA";&lt;/P&gt;
&lt;P style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; background-color: #ffffff;"&gt;return;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;I wasn't envisioning a %include here, and I haven't specifically ever done it this way. I don't think it would work that way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I was envisioning was copying and pasting the code from FileA to replace the %include statement. Same for FileB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And of course, whatever is in FileA and FileB must be code that can execute in a single data step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DBailey has explained how to do this with macros.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 20:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91007#M19244</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-03-27T20:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91008#M19245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For an advanced discussion of this topic, I would recommend:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Conditionally_Executing_Global_Statements" title="http://www.sascommunity.org/wiki/Conditionally_Executing_Global_Statements"&gt;http://www.sascommunity.org/wiki/Conditionally_Executing_Global_Statements&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The author, Ron Fehd, has forgotten more about SAS coding than I can begin to know, and I find myself going back to this article every so often to solve a complex conditional execution problem with some elegant IFC() coding magic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;Karl&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 20:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91008#M19245</guid>
      <dc:creator>KarlK</dc:creator>
      <dc:date>2013-03-27T20:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91009#M19246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can easily do conditional %INCLUDEs using CALL EXECUTE:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let colour = blue;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; colour = "&amp;amp;colour";&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; if colour='blue' then call execute ('%include "program1.sas";');&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; else if colour='red' &lt;SPAN style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;then call execute ('%include "program2.sas";');&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You just need to make sure that whatever you put in your call execute is a syntactically-correct statement(s).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Mar 2013 01:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91009#M19246</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2013-03-28T01:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91010#M19247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I read that page and see that this code can be used to conditionally execute % includes by replacing the %put with the %include.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, how do i set options conditional on colour? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options source2;&lt;/P&gt;&lt;P&gt;%sysfunc(ifc(%sysfunc(getoption(source2)) eq SOURCE2&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,%nrstr(%put true*;)&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,%nrstr(%put *false;)&lt;/P&gt;&lt;P&gt;&amp;nbsp; ));&lt;/P&gt;&lt;P&gt;options nosource2;&lt;/P&gt;&lt;P&gt;%sysfunc(ifc(%sysfunc(getoption(source2)) eq SOURCE2&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,%nrstr(%put true*;)&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,%nrstr(%put *false;)&lt;/P&gt;&lt;P&gt;&amp;nbsp; ));&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Mar 2013 16:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91010#M19247</guid>
      <dc:creator>jjjames</dc:creator>
      <dc:date>2013-03-31T16:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91011#M19248</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I originally tried to use call execute...but that code seems as though it would always execute program 1?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let colour = blue;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data _null_;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; colour = "&amp;amp;colour";&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; if colour='blue' then call execute ('%include "program1.sas";');&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; else if colour='red' &lt;SPAN style="font-style: inherit;"&gt;then call execute ('%include "program2.sas";');&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Mar 2013 16:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91011#M19248</guid>
      <dc:creator>jjjames</dc:creator>
      <dc:date>2013-03-31T16:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91012#M19249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to explain more what you want to happen and when.&amp;nbsp; You mention two code files and in the same breath talk about variables, as if you mean data files instead of code files.&amp;nbsp; Then you use IF statements that make it seem as if you want different things to happen for different observations of the same data step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So what do the two files do?&amp;nbsp; Are they full programs with multiple data and proc steps?&amp;nbsp; Are they fragments of code to be embedded into a single data step?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the IF COLOR='blue' condition being test against? Is it a single observation of a data set?&amp;nbsp; If so is it possible that a single dataset will have records with both blue and red values?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to conditionally determine which piece of code is include perhaps you can conditionally generate a FILEREF and then use the fileref in the %INCLUDE statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; if "&amp;amp;color" = "blue" then filename('STEP2',"file1.sas");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; else if "&amp;amp;color" = "red" then filename('STEP2',"file2.sas");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%include step2;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Mar 2013 16:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91012#M19249</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-03-31T16:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91013#M19250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your reply and sorry about being unclear I am relatively new to coding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So in a data step I have a variable 'colour' which can take either of two values: "red" or "blue" and I have two external files which contain several numerical variables hard coded to certain values. Each external file contains different values for each variable. These external files are updated elsewhere so I cannot change this format (Using % include). I basically want to include the one set if colour is blue and the other if red. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Mar 2013 17:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91013#M19250</guid>
      <dc:creator>jjjames</dc:creator>
      <dc:date>2013-03-31T17:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91014#M19251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp; I'm having a hard time envisioning WHAT your "red" or "blue" files actually contain. At first, it sounded like they contained program code, because you said that they contained code. But now, in your more recent explanation, you said that the external files "contain several numerical variables hard-coded to certain values" -- that doesn't sound like code, that sounds like data. And, you further explained that the external files "are updated elsewhere so you cannot change this format" -- again ,that sounds like DATA, not CODE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; So, now, the problem sounds different than it did initially. Can you post an example of what is in the first file with the "red" or "blue" and example of the code or data in the 2 external files? I really feel like a concrete sample of your data would help and would eliminate the guessing about what you have and what you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; When you say that you want to "include the one set if colour is blue" and "the other if red" almost sounds to me like you want to go read a different external file based on some other variable value in the first file. Again, unless the two external files have "datalines" embedded in the program code, I am not sure now that the %include method is the right method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; The rule of thumb, when trying to code a macro solution to anything is to start with a working SAS program without any macro references.&amp;nbsp; So, do you have PROGRAM1.SAS and PROGRAM2.SAS to "include" or do you have DATA1.TXT and DATA2.TXT that you want to read conditionally? Can you show examples of the "real" code that you have and what is in your 3 files? That would be a big help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cynthia&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Mar 2013 18:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91014#M19251</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2013-03-31T18:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91015#M19252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Post examples please.&lt;/P&gt;&lt;P&gt;Guessing from your description you have two program files with hard coded SAS assignment statements.&lt;/P&gt;&lt;P&gt;Such as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;weight=105;&lt;/P&gt;&lt;P&gt;length=47.5 ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If so then you want to %INCLUDE both files, but place the %INCLDUE's inside of IF /THEN/ELSE contruct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data new ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set old;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if color='blue' then do;&lt;/P&gt;&lt;P&gt;%include 'bluefile.sas';&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt; else do;&lt;/P&gt;&lt;P&gt;%include 'redfile.sas';&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If instead the files contain just data (such as a CSV file or other ways to store data) the solution would be different.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Apr 2013 02:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91015#M19252</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-04-01T02:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91016#M19253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;Thanks for your reply and sorry about being unclear I am relatively new to coding.
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;So in a data step I have a variable 'colour' which can take either of two values: "red" or "blue" and I have two external files which contain several numerical variables hard coded to certain values. Each external file contains different values for each variable. These external files are updated elsewhere so I cannot change this format (Using % include). I basically want to include the one set if colour is blue and the other if red.&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;It would still help to see an example of these external files.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nevertheless, it sounds like instead of %include, you could simply use a SAS data step to read the contents of the external file. Then your branching is much simpler, using a macro and macro variables.&lt;/P&gt;&lt;P&gt;%macro oink;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call symputx('colour',colour);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%if &amp;amp;colour=blue %then filename "file A"%str(;);&lt;/P&gt;&lt;P&gt;%else %if &amp;amp;colour="red" %then filename "file B"%str(;);&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%oink&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;followed by the appropriate INPUT statements in a data step.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Paige Miller&#xD;
&#xD;
Code should have been macro statements, this is corrected now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Apr 2013 15:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91016#M19253</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-04-01T15:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91017#M19254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks again for all the replies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As Tom suggested^^ the external files are both .sas files with simple hard coded assignment statements. E.g.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;File A:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;width=196;&lt;/P&gt;&lt;P&gt;length=100;&lt;/P&gt;&lt;P&gt;depth=250;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;File B:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;width=200;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;length=450;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;depth=65;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;there is a process elsewhere which reads an excel data set and generates this simple code ^ which I need to read in conditionally on my variable 'colour' being either "red" or "blue"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: rgba(255, 255, 255, 0);"&gt;thanks again&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Apr 2013 16:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91017#M19254</guid>
      <dc:creator>jjjames</dc:creator>
      <dc:date>2013-04-01T16:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91018#M19255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So in that case you do not want to conditionally include the files, instead you want to conditionally execute the code that the files contain.&amp;nbsp; So place the %INCLUDE statements inside of logic blocks so that they execute at the appropriate place.&amp;nbsp; Because you are not reading these variables from either a source dataset or via INPUT statement the values will by default be retained, so you might want to worry about clearing the values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if colour = 'BLUE' then do;&lt;/P&gt;&lt;P&gt;%include 'file A'&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt; else if colour='RED' then do;&lt;/P&gt;&lt;P&gt;%include 'file B';&lt;/P&gt;&lt;P&gt; end;&lt;/P&gt;&lt;P&gt; output;&lt;/P&gt;&lt;P&gt; call missing (of _all_);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Apr 2013 16:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91018#M19255</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-04-01T16:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional %INCLUDE Statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91019#M19256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I use the following method (careful with the semicolons):&lt;/P&gt;&lt;P&gt;1. Define a macro like this:&lt;/P&gt;&lt;P&gt;%macro do_if(a);&lt;/P&gt;&lt;P&gt;%if &amp;amp;a %then&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let c=;&lt;/P&gt;&lt;P&gt;%else&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let c=*;&lt;/P&gt;&lt;P&gt;&amp;amp;c&lt;/P&gt;&lt;P&gt;%mend do_if;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Use it like this:&lt;/P&gt;&lt;P&gt;%do_if(&amp;amp;var = red) %include "red.sas";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works by commenting out the rest of the line up to the final semicolon when the condition is false. An even simpler way is to use a variable which could contain * and just place it at the start of the line. The logic is not so self-documenting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;star %include "blue.sas";&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Apr 2013 09:16:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-INCLUDE-Statements/m-p/91019#M19256</guid>
      <dc:creator>Peter_L</dc:creator>
      <dc:date>2013-04-02T09:16:19Z</dc:date>
    </item>
  </channel>
</rss>

