BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jacksonan123
Lapis Lazuli | Level 10

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.?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

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").

 

jacksonan123
Lapis Lazuli | Level 10
I followed your bullet point #1 and I did output a batch file titled
boot1.bat using this code:

DATA _NULL;

LENGTH MYOUT $200;

FILE '/folders/myfolders/BOOTSTRAP_PED/BATFILEPREP/boot1.bat'
FILENAME=MYOUT;

PUT MYOUT;

RUN;

The file contents was the path name

/folders/myfolders/BOOTSTRAP_PED/BATFILEPREP/boot1.bat

which I do not want. If boot1.bat were empty that would be best.

I have not tried your point #2 but maybe you can address the question that
if I follow point #2 will that allow me to populate boot1.bat with

NMGO TEST1.CTL -MAXLIM=3?
Tom
Super User Tom
Super User

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?

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 478 views
  • 1 like
  • 3 in conversation