BookmarkSubscribeRSS Feed
J_S_
Calcite | Level 5
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 0 replies
  • 572 views
  • 0 likes
  • 1 in conversation