<?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: %include - conditional in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74940#M16149</link>
    <description>Thanks Scott, for the call execute idea.  I didn't know about that one.  Here's what I've come up with:&lt;BR /&gt;
&lt;BR /&gt;
%macro logo;                                                                                                                            &lt;BR /&gt;
%include "\\technology\AMLogo.sas";                                             &lt;BR /&gt;
%mend logo;                                                                                                                             &lt;BR /&gt;
                                                                                                                                        &lt;BR /&gt;
                                                                                                                                        &lt;BR /&gt;
data _null_;                                                                                                                            &lt;BR /&gt;
if day(today()) in (1,7) then call execute('%logo');                                                                                    &lt;BR /&gt;
run;</description>
    <pubDate>Wed, 07 Oct 2009 17:58:21 GMT</pubDate>
    <dc:creator>Bill</dc:creator>
    <dc:date>2009-10-07T17:58:21Z</dc:date>
    <item>
      <title>%include - conditional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74938#M16147</link>
      <description>I have a program that runs at various times that contains an %include statement to call in another program.  I'd like the %include statement to execute conditionally.  I don't have correct syntax and I get the error indicated.  What is the correct syntax for this?  Thanks. (SAS9.1 on Windows)&lt;BR /&gt;
&lt;BR /&gt;
815   data _null_;&lt;BR /&gt;
816   if day(today()) in (1,5) then&lt;BR /&gt;
817   %include "\\technology\AMLogo.sas";&lt;BR /&gt;
818  +**********&lt;BR /&gt;
      --&lt;BR /&gt;
      180&lt;BR /&gt;
&lt;BR /&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.</description>
      <pubDate>Wed, 07 Oct 2009 17:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74938#M16147</guid>
      <dc:creator>Bill</dc:creator>
      <dc:date>2009-10-07T17:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: %include - conditional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74939#M16148</link>
      <description>The approach taken will depend - if you have conditional code to execute within the current DATA step, wrap it in an IF &lt;CONDITION&gt; THEN DO; &lt;YOUR include=""&gt;; END;  &lt;BR /&gt;
&lt;BR /&gt;
Also, review the CALL EXECUTE command in DATA step programming, however that code will not execute until the current DATA step completes.  Suggest coding a RUN; to terminate DATA steps, especially with this coding situation.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/YOUR&gt;&lt;/CONDITION&gt;</description>
      <pubDate>Wed, 07 Oct 2009 17:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74939#M16148</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-10-07T17:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: %include - conditional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74940#M16149</link>
      <description>Thanks Scott, for the call execute idea.  I didn't know about that one.  Here's what I've come up with:&lt;BR /&gt;
&lt;BR /&gt;
%macro logo;                                                                                                                            &lt;BR /&gt;
%include "\\technology\AMLogo.sas";                                             &lt;BR /&gt;
%mend logo;                                                                                                                             &lt;BR /&gt;
                                                                                                                                        &lt;BR /&gt;
                                                                                                                                        &lt;BR /&gt;
data _null_;                                                                                                                            &lt;BR /&gt;
if day(today()) in (1,7) then call execute('%logo');                                                                                    &lt;BR /&gt;
run;</description>
      <pubDate>Wed, 07 Oct 2009 17:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74940#M16149</guid>
      <dc:creator>Bill</dc:creator>
      <dc:date>2009-10-07T17:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: %include - conditional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74941#M16150</link>
      <description>It is my understanding that the %INCLUDE statement is a compile time statement and cannot be conditionaly executed by a data step.  It will need to be handled in the MACRO language.  Something like this:&lt;BR /&gt;
-----------------------------------------&lt;BR /&gt;
%macro AMLogoTest;&lt;BR /&gt;
  %let today =  %sysfunc(day(%sysfunc(today())));&lt;BR /&gt;
  %put Today = &amp;amp;Today;&lt;BR /&gt;
  %if &amp;amp;today = 1 or &amp;amp;today = 5 %then %do;&lt;BR /&gt;
     %put Run the AMLogo code;&lt;BR /&gt;
     %include "\\technology\AMLogo.sas";&lt;BR /&gt;
  %end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%AMLogoTest;</description>
      <pubDate>Wed, 07 Oct 2009 18:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74941#M16150</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2009-10-07T18:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: %include - conditional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74942#M16151</link>
      <description>And, to add to what Curtis suggests, this user group paper has a very good intro to Macro concepts and Macro conditional logic:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi28/056-28.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/056-28.pdf&lt;/A&gt;&lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 07 Oct 2009 18:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74942#M16151</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-10-07T18:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: %include - conditional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74943#M16152</link>
      <description>Thanks Cynthia,&lt;BR /&gt;
My solution can of course be shorted to:&lt;BR /&gt;
-----------------------------&lt;BR /&gt;
%macro AMLogoTest;&lt;BR /&gt;
  %if %sysfunc(day(%sysfunc(today()))) = 1 or %sysfunc(day(%sysfunc(today()))) = 5 %then %include "\\technology\AMLogo.sas";&lt;BR /&gt;
%mend;&lt;BR /&gt;
%AMLogoTest;

Message was edited by: CurtisMack</description>
      <pubDate>Wed, 07 Oct 2009 20:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74943#M16152</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2009-10-07T20:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: %include - conditional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74944#M16153</link>
      <description>Why do you need to complicate matters by introducing a macro invocation, presuming that you have SAS DATA step code in your  program file \\technology\AMLogo.sas -- especially the lack of SAS statement numbers when using macros.&lt;BR /&gt;
&lt;BR /&gt;
A simple DO; / END; construct surrounding your %INCLUDE statement makes it oh so very simple and easier to maintain, debug, and understand.&lt;BR /&gt;
&lt;BR /&gt;
What's unclear - at least to me - is what type of SAS code is in your %INCLUDE file?&lt;BR /&gt;
&lt;BR /&gt;
Also, the very powerful RESOLVE DATA step function may be the ticket if you in fact have code that must be compiled on the fly as part of the DATA step processing.  Here is an example:&lt;BR /&gt;
&lt;BR /&gt;
1    %macro echoinfo;&lt;BR /&gt;
2    %global mystatus;&lt;BR /&gt;
3    %put right now, macro var mystatus is: &amp;amp;mystatus;&lt;BR /&gt;
4    %mend echoinfo;&lt;BR /&gt;
5    data _null_;&lt;BR /&gt;
6    call symput('mystatus','I am executing inside this DATA step!');&lt;BR /&gt;
7    x = resolve('%echoinfo');&lt;BR /&gt;
8    run;&lt;BR /&gt;
&lt;BR /&gt;
right now, macro var mystatus is: I am executing inside this DATA step!&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.03 seconds&lt;BR /&gt;
      cpu time            0.01 second&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 07 Oct 2009 20:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74944#M16153</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-10-07T20:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: %include - conditional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74945#M16154</link>
      <description>This is basicaly a style issue, and I posted my reply before seeing yours.&lt;BR /&gt;
&lt;BR /&gt;
That said,  I did not want to assume that the code in his included file could execute within the data step.  I personaly see no reason to call the data step just to call some simple functions.  In my opinion if all that is needed is some conditional execution of code, the call execute method is more confusing than the equivalent macro solution.  Mostly because it is too easy to assume that the code is executing durring the data step instead of after it.&lt;BR /&gt;
&lt;BR /&gt;
The resolve function is a good solution in many places, and can execute within the datastep.  It does make my comment about executing a %include inside a data step partially incorrent.  But as I said I did not want to assume what kind of code was inside that file and resolve assumes the contents would return a string that can be store inside a variable.  The logic might have been much more complex.  I also think that in this example it is harder to follow the logic.&lt;BR /&gt;
&lt;BR /&gt;
IMHO&lt;BR /&gt;
Curtis</description>
      <pubDate>Wed, 07 Oct 2009 21:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74945#M16154</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2009-10-07T21:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: %include - conditional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74946#M16155</link>
      <description>To CurtisMack - I am sorry about not being specific with my reply - please understand it was not to criticize your post.  I apologize since it may have been misconstrued.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 07 Oct 2009 21:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74946#M16155</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-10-07T21:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: %include - conditional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74947#M16156</link>
      <description>Scott,&lt;BR /&gt;
I just saw it as a difference of opinion that we were expressing.  You made no disparaging remarks, but thanks for clarifying things.&lt;BR /&gt;
Curtis</description>
      <pubDate>Wed, 07 Oct 2009 22:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/include-conditional/m-p/74947#M16156</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2009-10-07T22:16:05Z</dc:date>
    </item>
  </channel>
</rss>

