How to run multiple SAS programs from one single SAS program. A log file should also be created for each SAS program
Yes, it absolutely does that. If you want the output as well as the logs to be moved, you need to add to the macro:
%macro run_one (path);
proc printto log="&path.log";
run;
proc printto print="&path.lst";
run;
%include "&path.sas";
run;
%mend run_one;
Why?
If your requirement is separated logs, it's easier to call those programs in an external shell/dos script instead.
Where should the logs go? What should they be named?
Logs should be created at the same location as programs and should be named as programs. I tried running the below test.sas code in which I included multiple SAS programs, but it doesnt create the log files separately instead writing everything to test.log file. I would like to have the log files created for each SAS program, something like test2.log, test3.log, test4.log
Content of test.sas is as below.
%INCLUDE '\\XYZ\test2.sas';
%INCLUDE '\\XYZ\test3.sas';
%INCLUDE '\\XYZ\test4.sas';
Use PROC PRINTTO before each %include to create and direct the log file to where you want it.
Reeza and I are thinking alike. I would write a macro:
%macro run_one (path);
proc printto log="&path.log";
run;
%include "&path.sas";
run;
%mend run_one;
Then the trick is to call the macro properly:
%run_one (\\XYZ\test2.)
%run_one (\\XYZ\test3.)
Notice that the dot is part of the macro call, but not the extension of "sas". That makes it easier for the macro to specify both the log and the program.
Thanks Everyone. I tried using proc printto but it still writes the actual output in the original program log file. The log files for test2 and test3 has only the below information.
2 The SAS System Wednesday, June 29, 2016 03:48:46 PM
NOTE: PROCEDURE PRINTTO used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
NOTE: PROCEDURE CONTENTS used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
45
46 %run_one (T:\test2.)
Yes, it absolutely does that. If you want the output as well as the logs to be moved, you need to add to the macro:
%macro run_one (path);
proc printto log="&path.log";
run;
proc printto print="&path.lst";
run;
%include "&path.sas";
run;
%mend run_one;
I was wrong. It did work. Thanks everyone for the help.
@KBACHU Please mark the question Solved.
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.