I have a program that I run called NONMEM and it can be run from a batch file in a DOS command window with commands such as:
CALL NMGO TEST1.CTL -MAXLIM=3
CALL NMGO TEST2.CTL -MAXLIM=3
These can be combined into a batch file which I will call BOOT1 and there can be i=1 to n
CALL NMGO TEST(i).CTL -MAXLIM=3 lines of code as needed.
I have two questions:
1. How would one write such a text file in SAS, and
2. How would one go about using a macro to produce k such files with the (i) in CALL NMGO TEST(i).CTL -MAXLIM=3 varying and increasing depending on what one would want e.g.,
BOOT2 and BOOT3 are specific examples
BOOT2
CALL NMGO TEST3.CTL -MAXLIM=3
CALL NMGO TEST4.CTL -MAXLIM=3
and
BOOT3
CALL NMGO TEST5.CTL -MAXLIM=3
CALL NMGO TEST6.CTL -MAXLIM=3
while BOOT(k) is a general example
BOOT(k)
CALL NMGO TEST(i).CTL -MAXLIM=3
CALL NMGO TEST(i+1).CTL -MAXLIM=3
CALL NMGO TEST(i+2).CTL -MAXLIM=3
CALL NMGO TEST(i+3).CTL -MAXLIM=3
The actual range of k would be 1-10 and the range of (i) for CALL NMGO TEST(i).CTL -MAXLIM=3 within a BOOT(k) file would be:
BOOT(k) (i)=1-100 for k=1,
and for
BOOT(k+1) (i)=101-200 for k=2,
and for
BOOT(k+2) (i)=201-300 for k=3, etc.?
So you want to generate XX calls to NONMEM. You want store them into more than one batch files.
You could either specify the number of files you want and then calculate how many calls to write to each file.
Or specify the maximum number of calls to write to each file.
Let's do the latter.
%let num_runs=300;
%let max_runs_per_file=100;
data _null_;
length fname $256 testname $50 ;
do i=1 to &num_runs;
testname = cats('TEST',i,'.CTL');
modi = mod(i,&max_runs_per_file);
if 1=modi then batch+1;
fname = cats('/path/','boot',batch,'.bat');
file bat filevar=fname ;
if 1=mod1 then put 'REM ' batch= 'Starts with ' testname= ;
put 'CALL NMGO ' testname '-MAXLIM=3' ;
end;
run;
So this will create three files named boot1.bat, boot2,bat and boot3.bat in the directory /path/.
Each file will have a first line that is a comment that shows which file it is and which test/run number it starts with followed by up to 100 calls to NONMEM.
You're asking a whole set of questions here. What's your level of SAS expertise?
1. How to generate code and write it to an external file?
That's normally done using a Data _Null_; step with the FILE command. If you're using the Filevar option then you can even dynamically change the output file (example 5 here in the documentation)
2. How to execute the generated code?
If it's SAS code then you just use an %include statement. If you want to execute non-SAS code then you need to issue a OS level command. There are a few options within SAS to do so like the X statement or the Call System() routine.
SAS option XCMD must be set for SAS to be allowed to issue OS level commands (default is NOXCMD).
3. Be aware that all processing happens on the SAS Server side and whatever script you generate must be suitable for the OS where the SAS Server executes (so not your client PC unless you have a local SAS installation - "PC SAS").
Let's look at what you told SAS to do:
DATA _NULL;
LENGTH MYOUT $200;
FILE '/folders/myfolders/BOOTSTRAP_PED/BATFILEPREP/boot1.bat' FILENAME=MYOUT;
PUT MYOUT;
RUN;
Let's review the statements one by one.
First you define a variable called MYOUT as character with length of 200 bytes.
Then you tell SAS to create a file and set the variable MYOUT to the name of the file it is creating.
Then you write the value of the variable MYOUT to the file.
So it did what you asked. It created a file that contains its own name.
What do you WANT to do?
So you want to generate XX calls to NONMEM. You want store them into more than one batch files.
You could either specify the number of files you want and then calculate how many calls to write to each file.
Or specify the maximum number of calls to write to each file.
Let's do the latter.
%let num_runs=300;
%let max_runs_per_file=100;
data _null_;
length fname $256 testname $50 ;
do i=1 to &num_runs;
testname = cats('TEST',i,'.CTL');
modi = mod(i,&max_runs_per_file);
if 1=modi then batch+1;
fname = cats('/path/','boot',batch,'.bat');
file bat filevar=fname ;
if 1=mod1 then put 'REM ' batch= 'Starts with ' testname= ;
put 'CALL NMGO ' testname '-MAXLIM=3' ;
end;
run;
So this will create three files named boot1.bat, boot2,bat and boot3.bat in the directory /path/.
Each file will have a first line that is a comment that shows which file it is and which test/run number it starts with followed by up to 100 calls to NONMEM.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.