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)
815 data _null_;
816 if day(today()) in (1,5) then
817 %include "\\technology\AMLogo.sas";
ERROR 180-322: Statement is not valid or it is used out of proper order.
The approach taken will depend - if you have conditional code to execute within the current DATA step, wrap it in an IF THEN DO; ; END;
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.
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:
%let today = %sysfunc(day(%sysfunc(today())));
%put Today = &Today;
%if &today = 1 or &today = 5 %then %do;
%put Run the AMLogo code;
My solution can of course be shorted to:
%if %sysfunc(day(%sysfunc(today()))) = 1 or %sysfunc(day(%sysfunc(today()))) = 5 %then %include "\\technology\AMLogo.sas";
Message was edited by: CurtisMack
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.
A simple DO; / END; construct surrounding your %INCLUDE statement makes it oh so very simple and easier to maintain, debug, and understand.
What's unclear - at least to me - is what type of SAS code is in your %INCLUDE file?
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:
1 %macro echoinfo;
2 %global mystatus;
3 %put right now, macro var mystatus is: &mystatus;
4 %mend echoinfo;
5 data _null_;
6 call symput('mystatus','I am executing inside this DATA step!');
7 x = resolve('%echoinfo');
right now, macro var mystatus is: I am executing inside this DATA step!
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.01 second
This is basicaly a style issue, and I posted my reply before seeing yours.
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.
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.