简体   繁体   中英

How can I force SAS to wait for a command to fully execute?

I've got a bit of an issue with having my SAS sessions kick off, and subsequently wait for Python scripts to complete. I'm using Python for a Bag-of-Words analysis with some Sentiment analysis thrown in for flavor, and the script executes just fine, but SAS keeps going after kicking it off. This presents a problem, because the rest of the SAS program requires the results of the Python script to run properly.

I've tried to use the waitfor all command in SAS, but that doesn't seem to work for this particular issue.

Here's the code I'm executing in SAS:

%pScript_loc=path\pythonTester.py; /* LOCATION OF THE PROGRAM */
filename temp pipe "otherPath\python.exe &pScript."; /* LOCATION OF PYTHON EXECUTABLE */
data _null_;
infile temp;
input;
put _infile_;
run;

waitfor _all_;

This should make sure that the SAS program kicks the Python program off, but doesn't seem to be effective at making SAS wait for Python to do its thing.

Try using the x command rather than a data _null_ step. xsync is turned on by default in SAS, meaning that the OS will not return control to SAS until the Python script completes.

%let %pScript_loc=path\pythonTester.py;

x "otherPath\python.exe &pScript.";

You can also optionally use the saspy package and do everything from there, skipping the SAS editor altogether.

waitfor is exclusive for systask with filename it is a little bit different

filename x pipe 'dir';
data _NULL_;
  infile x DLM='$';
  length str $80;
  input str;
  put str;
run;
data _NULL_;
  infile x DLM='$';
  length str $80;
  input str;
  put str;
run;

each time a datastep access file the pipe is opened and read until closed. That means you can open the same time twice and there is no need to wait for end of program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM