BookmarkSubscribeRSS Feed
Bill
Quartz | Level 8
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";
818 +**********
--
180

ERROR 180-322: Statement is not valid or it is used out of proper order.
9 REPLIES 9
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

Scott Barry
SBBWorks, Inc.
Bill
Quartz | Level 8
Thanks Scott, for the call execute idea. I didn't know about that one. Here's what I've come up with:

%macro logo;
%include "\\technology\AMLogo.sas";
%mend logo;


data _null_;
if day(today()) in (1,7) then call execute('%logo');
run;
CurtisMack
Fluorite | Level 6
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:
-----------------------------------------
%macro AMLogoTest;
%let today = %sysfunc(day(%sysfunc(today())));
%put Today = &Today;
%if &today = 1 or &today = 5 %then %do;
%put Run the AMLogo code;
%include "\\technology\AMLogo.sas";
%end;
%mend;
%AMLogoTest;
Cynthia_sas
SAS Super FREQ
And, to add to what Curtis suggests, this user group paper has a very good intro to Macro concepts and Macro conditional logic:
http://www2.sas.com/proceedings/sugi28/056-28.pdf
cynthia
CurtisMack
Fluorite | Level 6
Thanks Cynthia,
My solution can of course be shorted to:
-----------------------------
%macro AMLogoTest;
%if %sysfunc(day(%sysfunc(today()))) = 1 or %sysfunc(day(%sysfunc(today()))) = 5 %then %include "\\technology\AMLogo.sas";
%mend;
%AMLogoTest; Message was edited by: CurtisMack
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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');
8 run;

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


Scott Barry
SBBWorks, Inc.
CurtisMack
Fluorite | Level 6
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.

IMHO
Curtis
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

Scott Barry
SBBWorks, Inc.
CurtisMack
Fluorite | Level 6
Scott,
I just saw it as a difference of opinion that we were expressing. You made no disparaging remarks, but thanks for clarifying things.
Curtis

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1604 views
  • 0 likes
  • 4 in conversation