- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
I have a helloworld.py python script and I want to execute it in SAS Enterprise Guide, how could I do it and see the "Hello World!" output?
My SAS code in EG is as follow, but it did not work:( Please help me and let me know how I can revise the code and see the "Hello World!" output?
data test;
x "cd /home/Jade";
x "python helloworld.py";
output;
Run;
Thank you!
Jade
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
X is a global statement that is executed immediately when encountered in code. So your two X statements are dealt with while the data step is compiled, not while it runs.
To catch output from external commands, use filename pipe:
filename oscmd pipe "python /home/Jade/helloworld.py 2>&1";
data test;
infile oscmd truncover;
input infile $100.;
run;
The 2>&1 construct redirects stderr output to stdout, so everything (output and/or error messages) can be read from the pipe.
To write output into the SAS log, do
data _null_;
infile oscmd;
input;
put _infile_;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You will need to be more specific about "it did not work".
First, I would include full paths to the relevant parts, it looks like you have EG installed on a unix system, I am not realy familiar with that setup. In Windows if Python was installed in c:\python and the python script in c:\myscripts then the X command would look:
x '"c:\python\python.exe" "c:\myscripts\helloworld.py"';
So that may be a problem for you - i.e. it isn't finding one or the other. It may also be that you don't have access rights. It could also be that the script did run, but the output went so quickly you didn't see it. You could try putting in your python code a promtp to get a response, something like:
"Press any key to continue"
This way the window will stay active until a key press.
Further information is required really.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
X is a global statement that is executed immediately when encountered in code. So your two X statements are dealt with while the data step is compiled, not while it runs.
To catch output from external commands, use filename pipe:
filename oscmd pipe "python /home/Jade/helloworld.py 2>&1";
data test;
infile oscmd truncover;
input infile $100.;
run;
The 2>&1 construct redirects stderr output to stdout, so everything (output and/or error messages) can be read from the pipe.
To write output into the SAS log, do
data _null_;
infile oscmd;
input;
put _infile_;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
1. Make sure the command works from the command line.
2. Make sure x command is enabled in EG - usually turned off by default.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And as @RW9 has suggested, also use the full path to your python binary, for security reasons.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you all! The python script worls in linux command and the X windows is eabled in SAS.
What KurtBremser suggested worked!!! Finally I saw the output in EG.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, you can run the x cmd directly without data step:
x "cd /home/Jade";
x "python helloworld.py";