11-05-2012 10:22 AM
I'm trying to accomplish the following.
I have a program, which I want to call itself once. So if the name of my program is test.sas, then I figure I need something in lines of the following:
<bulk of program>
do this once:
Through the first run of the program, it should run like it uses to, but through the second run, I want to change a parameter. I imagine that the bulk of the program should contain code similar to:
%if &ok %then %do;
So I suppose that I would also like the variable &ok to be set to 1, when the program is run for the second time, and before that the parameter should be 0.
For some reason, my own attempts ended up in infinite loops.
11-05-2012 10:28 AM
Wrap it in macro code instead.
Assuming you save the code in another sas program as my_program.sas
%macro my_program (age=my_value);
proc print data=sashelp.class;
%include my_program.sas; *if its in a separate program file;
11-05-2012 11:20 AM
: The forum could probably provide a better answer if you describe what you are trying to accomplish in less general terms. That said, I agree with Fareeza, but will guess that you want to include the condition in a %do %while loop in the macro. You just have to insure that you have defined the condition such that it won't run infinitely if the condition is never met. e.g., you can make it an or condition like if some criterion is reached or you have exceeded X iterations.
11-09-2012 11:45 AM
%include is not a macro invocation, but rather something like a "compiler directive" in other computer languages. This affects the timing when exactly the source is "included," which is earlier than the timing expected by a macro invocation.
Anyway, I agree with Arthur in that there may be a better way to implement what you are trying to do. But, if you insist, then here is something close to what you asked for.
/* save this file as c:\temp\test.sas before you submit it */
x cd "c:\temp\";
%put this is the <bulk> &=ok;
if not symexist("ok") then do;
call execute('%global ok; %let ok=0;');
call execute('%let ok=1;');
call execute('%include "c:\temp\test.sas";');
end; else do;
call execute('%symdel ok;');
/* on log -- some notes removed
this is the <bulk> OK=0
this is the <bulk> OK=1