SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to execute python helloworld.py in SAS Enterprise Guide

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 111
Accepted Solution

How to execute python helloworld.py in SAS Enterprise Guide

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 workSmiley Sad 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


helloworld.PNG

Accepted Solutions
Solution
‎02-27-2017 09:45 AM
Super User
Posts: 6,928

Re: How to execute python helloworld.py in SAS Enterprise Guide

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;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Super User
Posts: 7,392

Re: How to execute python helloworld.py in SAS Enterprise Guide

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.

Solution
‎02-27-2017 09:45 AM
Super User
Posts: 6,928

Re: How to execute python helloworld.py in SAS Enterprise Guide

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;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 17,784

Re: How to execute python helloworld.py in SAS Enterprise Guide

1. Make sure the command works from the command line. 

2. Make sure x command is enabled in EG - usually turned off by default. 

Super User
Posts: 6,928

Re: How to execute python helloworld.py in SAS Enterprise Guide

And as @RW9 has suggested, also use the full path to your python binary, for security reasons.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 111

Re: How to execute python helloworld.py in SAS Enterprise Guide

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.

 

New Contributor
Posts: 2

Re: How to execute python helloworld.py in SAS Enterprise Guide

Hi, you can run the x cmd directly without data step:

 

x "cd /home/Jade";

x "python helloworld.py";

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 782 views
  • 2 likes
  • 5 in conversation