BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
MM88
Calcite | Level 5

Hi community,

 

I would like to call a python program for each row of my dataset. My dataset has 4 variables, that I need to pass as parameters to the python call.

 

data _null_;
  set mydataset;
  command = 'python C:\temp\mypython.py ' || " " || quote(strip(var1)) || " " || quote(var2) || " " || quote(var3) || " " || quote(var4);
  X command;
run;

But no python call is executed.

Any suggestions of what could be the problem?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

That is not how the X (aka SYSTEM) command works.

 

You could do it with a pipe instead.

data _null_;
  set mydataset;
  length command $200;
  command = catx(' ','python C:\temp\mypython.py',quote(trim(var1)),quote(trim(var2)),quote(trim(var3)),quote(trim(var4)));
  infile cmd pipe filevar=command end=eof;
  do while not(eof);
    input;
    put _infile_;
  end;
run;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

That is not how the X (aka SYSTEM) command works.

 

You could do it with a pipe instead.

data _null_;
  set mydataset;
  length command $200;
  command = catx(' ','python C:\temp\mypython.py',quote(trim(var1)),quote(trim(var2)),quote(trim(var3)),quote(trim(var4)));
  infile cmd pipe filevar=command end=eof;
  do while not(eof);
    input;
    put _infile_;
  end;
run;
MM88
Calcite | Level 5
Thanks @Tom, it works your solution. Only in my system expects parenthesis in:
do while (not(eof));
Regards
Ksharp
Super User
/*
You could make a BAT file and execute it by X command.
*/
filename x 'c:\temp\run.bat';   /*<--Here is a BAT file to run SHELL command*/
data _null_;
  set mydataset;
  command = 'python C:\temp\mypython.py ' || " " || quote(strip(var1)) || " " || quote(var2) || " " || quote(var3) || " " || quote(var4);
file x;
put command ;
run;

options noxwait;
X 'c:\temp\run.bat';  /*<--Here is a BAT file to run SHELL command*/

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1162 views
  • 3 likes
  • 3 in conversation