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*/

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1201 views
  • 3 likes
  • 3 in conversation