Run All Your SAS® Programs in One Program: Automatically
Run All Your SAS® Programs in One Program: Automatically
Run All Your SAS® Programs in One Program: Automatically
PS010
Run All Your SAS® Programs in One Program: Automatically
Ling Y. Chen, Rho, Inc., Newton, MA
Steven A. Gilbert, Rho, Inc., Newton, MA
ABSTRACT
After SAS programs have been developed in an interactive computer environment, running them together in batch can save
time and avoid errors. This paper describes how to use SAS to create a .BAT file that automatically lists and runs all SAS
programs in a specified directory. A macro is presented that extends this procedure to an unlimited number of directories. The
codes included in this paper were tested using SAS V6.12 on the Windows 98 operating system.
INTRODUCTION
For a clinical trial study, there are usually three stages of programming needed to create the necessary output for inclusion in
a clinical trial study report. The first stage is called the “development” stage, during which we write the individual SAS
programs and test them for bugs. This stage, which typically uses a “first cut” of the study data, may be quite lengthy if there
are significant changes to the database prior to locking. The second stage occurs after final database lock when the programs
are run again and put through one last round of quality control. The quality control procedure used at this point is quite
extensive and includes a manual review of all program logs. The programs will not be allowed to have any error messages
and all warning messages will be checked and documented. Finally, when the programs have successfully completed the in-
house quality control process we are ready for the third and final “production” stage. During the production stage it is usually
desirable to produce a final copy of the output that has the same date stamp on all documents for the clinical study report.
Depending on the size of the study, there are sometimes dozens or even hundreds of programs that need to be run at the
production stage. Physically opening up, sitting through the run, and then closing each program can be tedious and time
consuming. It is also quite likely that either a necessary program is not run or some sequence-dependent programs are not run
in the proper order. Fortunately, these problems can be avoided by running the SAS programs in batch.
Note that this code assumes your SAS is installed in the C:\SAS directory. You may need to adjust the path to your particular
setup.
This .BAT file, when double clicked, will run C:\chen\prog1.sas first, then C:\chen\prog2.sas, and finally C:\chen\prog3.sas.
will generate a text file called proglist in the C:\ directory. This list can be generated in SAS by adding an X in front of the DOS
command:
x “dir c:\ >proglist.txt”
NESUG 16 Posters
Note, however, that this command creates a file in the C:\ directory. If you want to generate a file in the same directory as the
programs, then use the following code:
x “dir c:\chen >c:\chen\proglist.txt”
data progs;
infile proglist;
input @1 var1 $ @10 var2 $;
run;
data progs;
set progs;
char=”start/w c:\sas\sas.exe –sysin c:\chen”;
var3=char||compress(var1)||’.sas’;
where var2=’SAS’;
run;
Note that VAR1 captures the names of the files and VAR2 contains the extension of the files so that files with a .SAS
extension can be selected. VAR3 is the concatenated character variable that makes up the content of the .BAT file. The end
result is a data set containing a line of code containing the name of the program for each program in that directory.
data progs;
infile proglist;
input @1 var1 $ @10 var2 $;
run;
data &dsn;
set progs;
NESUG 16 Posters
%mend genlist;
Each time the macro is called, a data set is generated containing the list of programs for a particular folder. This can be
repeated for as many folders as desired. These data sets are then concatenated and written to a single .BAT file.
data all;
set chen gilbert;
run;
data _null_;
file runprog;
set all;
put @1 var3;
run;
CONCLUSION
Once the .BAT file has been generated, it is just a matter of double clicking it in order to run your programs one after another
without any human intervention. A task that would otherwise require a programmer, a spare computer, and hours of waiting
time is now just two clicks away. Before you leave work, double click to start it, and by the time you arrive at work the next
day, you will have your programs nicely run with the same date stamp. You can also schedule the event to occur at a time
that is most convenient and efficient, (i.e., 2 o’clock in the morning). It is important to remember that there will not be any
human supervision of the .log files. Therefore, it is a good idea to use Windows, by right clicking on the program folder and
using the search dialog box, to search through the .log files for error and warning messages, even though all programs have
been through final QC.
REFERENCES
The following reference represents selected material from the SAS Institute web site and is a useful supplement to this
document:
• http://ftp.sas.com/techsup/download/technote/ts648/ts648.pdf
SAS is a registered trademark of the SAS Institute Inc. in the USA and other countries.
ACKNOWLEDGMENTS
We would like to thank Katherine Monti, Ph.D. for her comments on this paper.
NESUG 16 Posters
CONTACT INFORMATION
Your comments and questions are valued and encouraged. Contact the author at:
Ling Yun Chen
Rho, Inc.
199 Wells Ave, Suite 302
Newton, MA 02459
617-965-8000 x26
Fax: 617-965-8014
lchen@rhoworld.com