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
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;
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.
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;
1. Make sure the command works from the command line.
2. Make sure x command is enabled in EG - usually turned off by default.
And as @RW9 has suggested, also use the full path to your python binary, for security reasons.
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.
Hi, you can run the x cmd directly without data step:
x "cd /home/Jade";
x "python helloworld.py";
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.