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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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