BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jade_SAS
Pyrite | Level 9

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


helloworld.PNG
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Kurt_Bremser
Super User

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;
Reeza
Super User

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

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

Jade_SAS
Pyrite | Level 9

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.

 

sotojcr
Obsidian | Level 7

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

 

x "cd /home/Jade";

x "python helloworld.py";

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 6 replies
  • 8593 views
  • 4 likes
  • 5 in conversation