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
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;
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;
/*
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*/
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.