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*/
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.