One way would be to create a controlling SAS program whose job is to run any of your 200 plus programs using a %INCLUDE, then does the extra steps following it.
You could even pass a parameter into this controlling program which specifies which of your programs to run so you don't need to keep changing it all the time. This functionality is particularly useful when running your programs in batch mode.
@Babloo - the controlling program approach is really very simple:
%include "<MySASProgram.sas>"; * Put your program name here;
* Now add the code you want to run afterwards for each of your programs here;
<Common program code>
Then you could enhance it using SYSPARM: https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n1ug7uhp2d4vpmn149431l4pcucf.htm...
Start SAS like so: sas MyControlProgram.sas -sysparm = "MySASProgram"
data _null;
* This reads the value of sysparm;
MyProgramName = sysparm();
* This creates a %include statement then runs it;
call execute('%include "' !! strip(MyProgramName) !! '.sas";');
run;
Note, change the sysparm to change the program you want to run. The above program does not change at all.
Assuming this is still about writing job status information to some table and that you will be running your code in batch:
I've faced in the past a similar challenge where I had to add such processing at the beginning and the end of each job after everything had already been built and unit tested. The approach I've taken there:
1. Create an autocall macro for writing the status information
2. Add the call to this autocall macro via system options -initstmt and -termstmt as part of the batch string.
This approach allowed me to implement such loggin without having to touch the DIS jobs.
@Babloo wrote:
I want to add few steps at the end of all programs which is located in particular folder. One way to do this is adding INCLUDE statement in all the programs.
But I don't want to touch all the programs to do this task as there are 200+ program. Is there any other way to achieve this objective without touching all the programs?
Do it in the script that runs the programs. That way you do not have to touch any existing SAS codes.
At one point, your scheduler has to run SAS. Most likely this is done by running a shell script like sasbatch.sh which is found in the SASApp/BatchServer directory of your BI server configuration. Find that script (your StoneBranch admins can help you in that), make a copy of it, expand that copy so that a small SAS program which records information is run before and after the main call, and use that copy.
@Babloo wrote:
We're executing the program via scheduling tool called Stone Branch. So you
are suggesting me to add and call my program which I want to add in after
the completion of each program?
@Babloo wrote:
We're executing the program via scheduling tool called Stone Branch. So you
are suggesting me to add and call my program which I want to add in after
the completion of each program?
The scheduler will call SAS programs issuing a command like:
.../sasbatch.sh -sysin <.../your sas program.sas> .....
So here you can add the options -initstmt and -termstmt
I.e. if you want to execute your login macro right after the DIS code (passed in via -sysin) then it would be something like
.../sasbatch.sh -sysin <.../your sas program.sas> .....-termstmt '%mymacro()'
The macro itself will execute in the same session and though you can use in this macro any of the DIS generated global macro variables.
And what @Kurt_Bremser proposes is also a viable approach and something I've done successfully in the past.
....or you can also as a combination of both approaches add the -....stmt options to your copy of the sasbatch.sh - or eventually even better to a copy of sasbatch_usermods.sh
I don't understand this part 'you can also as a combination of both approaches add the -....stmt options to your copy of the sasbatch.sh - or eventually even better to a copy of sasbatch_usermods.sh'
@Babloo wrote:
I don't understand this part 'you can also as a combination of both approaches add the -....stmt options to your copy of the sasbatch.sh - or eventually even better to a copy of sasbatch_usermods.sh'
sasbatch.sh is just a shell script which takes input parameters and constructs a batch command line which it then executes. Because it's just a shell script you can amend it to do whatever else you need. If you look into the script then - if I remember right - there is already logic built which adds some of the required options if they haven't been passed in as parameters. You could extend this logic and also add -initstmt and -termstmt in the same manner.
The script is cascaded in the same way the config files and autoexecs are.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.