Thanks for this. So where do I place my regular SAS query in this program? And why the
** ... and this at the end ;
%startstop(beginning=0, lib=<YOUR LIBREF>);
has (begining=0, ) at the end? shouldnt this be a different number as we used =0 at the beginning for Program #1?
Should work just like this:
** THEN, IN YOUR PROGRAM #1 PUT THIS AT THE **END** ;
%startstop(beginning=0, lib=<YOUR LIBREF>);
** and in PROGRAMS #2 and higher, put this at the beginning: ;
%startstop(beginning=1, lib=<YOUR LIBREF>);
** ... and this at the end ;
%startstop(beginning=0, lib=<YOUR LIBREF>);
beginning=1 is just telling the macro to run the part of the code that's needed for the START of a program (for all those #2 and higher) -- it checks whether the 'continue' file exists, aborts if not, and deletes it and continues if so.
beginning=0 tells it to run the part of the code needed for the END of each program (creates the 'continue' file).
That should work, but I think the easiest solution is just the driver file proposed by @SASKiwi though -- just a program that %includes all of your other programs, in order. If you do that, I would suggest adding: OPTIONS ERRORABEND; to the top of the driver program. This will cause the program to *stop* if it encounters an error rather than going into syntax check mode and continuing. If you don't add this option and the programs have never run before (i.e., there are no datasets in existence from a previous run), syntax-check mode still seems to create empty datasets, which can be a little weird / misleading.
Thanks for your advice. I asked SASKiwi for an example of that %INCLUDE solution and where to use it and how.
It's really just something as simple as creating a driver program (we'll call it driver.sas) and running that program:
options errorabend;
%include "program #1";
%include "program #2";
%include "program #3";
* ... ;
Thanks for that. It is working however, the problem I have now is that I could only see the log related with the last SAS program code within the batch. when the first two SAS programs (program #1.sas and program #2.sas) are completed I could only see the log related with the program #3.sas as it is the last program within the batch. But I need to see all the logs related with all 3 programs
well, now I am getting something different. I can see all the logs combined from the run SAS programs (1 & 2) and thats how I want however, this time although there are some ERRORs in the first program (programm #1) batch still continues to the next program (program #2). That's strange because when I first tested your solution it worked but doesn't work.
@atesera wrote:
well, now I am getting something different. I can see all the logs combined from the run SAS programs (1 & 2) and thats how I want however, this time although there are some ERRORs in the first program (programm #1) batch still continues to the next program (program #2). That's strange because when I first tested your solution it worked but doesn't work.
Do the individual included programs change the ERRORABEND system option?
Can you describe your current scenario? You say:
"So, let's say I have 3 SAS programs under the batch ..."
A SAS batch job is not a group of programs that are run in series.
From what you have shared, others have guessed that you have a .bat file (or maybe a powershell script?) which is invoking multiple SAS sessions in series. Is that correct?
Can you please share the code for that script, just so that we can be clear that we're understanding your scenario? Or if you are using some other program to orchestrate the execution of a series of SAS programs, please provide the details on how your are doing this.
If you have a single Task Scheduler task which executes three SAS programs, please show the code / setup for that task.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.