DATA Step, Macro, Functions and more

Running multiple SAS programs from one program

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

Running multiple SAS programs from one program

How to run multiple SAS programs from one single SAS program. A log file should also be created for each SAS program


Accepted Solutions
Solution
‎06-30-2016 09:37 AM
Super User
Posts: 5,071

Re: Running multiple SAS programs from one 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;

View solution in original post


All Replies
Super User
Posts: 5,254

Re: Running multiple SAS programs from one program

Why?

If your requirement is separated logs, it's easier to call those programs in an external shell/dos script instead.

Data never sleeps
Super User
Posts: 5,071

Re: Running multiple SAS programs from one program

Where should the logs go?  What should they be named?

Contributor
Posts: 70

Re: Running multiple SAS programs from one program

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';

 

Super User
Posts: 17,745

Re: Running multiple SAS programs from one program

Use PROC PRINTTO before each %include to create and direct the log file to where you want it. 

Super User
Posts: 5,071

Re: Running multiple SAS programs from one program

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.

Contributor
Posts: 70

Re: Running multiple SAS programs from one 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.)

 

 

Solution
‎06-30-2016 09:37 AM
Super User
Posts: 5,071

Re: Running multiple SAS programs from one 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;

Contributor
Posts: 70

Re: Running multiple SAS programs from one program

I was wrong. It did work. Thanks everyone for the help.

Super User
Posts: 17,745

Re: Running multiple SAS programs from one program

@KBACHU Please mark the question Solved.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 560 views
  • 3 likes
  • 4 in conversation