DATA Step, Macro, Functions and more

"put" to a file during a loop in IML

Reply
N/A
Posts: 1

"put" to a file during a loop in IML

Hello.. I'm new at the SAS IML language and have run into a problem I'm unable to solve on my own.
For some background on why I'm looking to do this:
I'm utilizing SAS IML to analyze some data, then exporting pieces of that data to an outside program (which does operations too complicated for me to program directly into SAS), and then import a specific result back in, and perform another operation. The final export-import-analysis tasks are then done until a certain condition is met.
I have successfully coded the mechanisms to do this "manually", meaning that it works if i want to run the code iteratively once, twice, and so on. To do this I can simply copy the last half of the code over and over to equal the number of iterations I desire. However, I want to allow the code to execute until a desired end is met, which may require 1 to 10 cycles of the code.

The problem I have encountered is that IML does not seems to write data to a text file until the end of a loop. I'm writing data to a text file, then executing a batch program.
As a simple example to describe my problem:
----------------
proc iml;
matorig=repeat(1,20,3);
file "c:\test\test.txt";
do i=1 to 20;
a=matorig[i,1];
b=matorig[i,2];
c=matorig[i,3];
put a b c;
end;
closefile "c:\test\test.txt";
X "c:\test\batchfile.bat";
quit;
-----------------
The above code will write 3 columns of 1s to the "text.txt" file and then executes a batch file to manipulate the file.
I can copy the code twice, to output the file, execute the batch, output the file again, and execute the batch again.
However, I need to execute it within a do loop (ultimately a do until or a do while) such as:
----------------
proc iml;
do looping=1 to 2;
matorig=repeat(1,20,3);
file "c:\test\test.txt";
do i=1 to 20;
a=matorig[i,1];
b=matorig[i,2];
c=matorig[i,3];
put a b c;
end;
closefile "c:\test\test.txt";
X "c:\test\batchfile.bat";
end;
quit;
-----------------

When this is ran, the text file is not created until the end of the do-loop, meaning it is not existent in the "c:\test\" directory until after the X-batch file is already ran. The test.txt file need to be created to the directory, and then the batch file ran. I can't figure out how to do this within a loop.

I apologize if I am not describing my problem well. Any assistance any of you may offer would be greatly appreciated.
-Jacob
Ask a Question
Discussion stats
  • 0 replies
  • 91 views
  • 0 likes
  • 1 in conversation