I have a SAS script from which I need to launch a Python script. I need the SAS script to find the first path to a "python.exe" file from the PATH environment variable, rather than hardcoding a path to a particular python installation.
This is the code I am attempting to use:
%let progdir = C:\Temp\scripts;
%let pypath = C:\Temp\pypath.txt;
x "if exist &pypath (del &pypath /Q)";
x "for %i in (python.exe) do @echo.%~$PATH:i >> &pypath"; run;
data null; infile "&pypath" length=reclen obs=1;
input location $varying254. reclen;
call symput('runpython', trim(location));
run;
x "%bquote(&runpython) &progdir./gtfs_collapse_routes.py";
x "if exist &pypath (del &pypath /Q)"; run;
The second x
call seems to be executed correctly, as the &pypath
file is created with the expected contents. However, this code is resulting in a SAS warning that I would like to eliminate:
WARNING: Apparent invocation of macro I not resolved.
This is obviously a reference to the %i
in the second x
call, but I am at a loss as to how to avoid this warning. (I originally wanted to get the python path using x "where python >> &pypath"
, but for unknown reasons that was failing to create a file at all even though that command works when run from cmd.exe.)
After a helpful prod in the right direction from @Joe, this is my updated, working code for obtaining the python path without a warning:
%let command = %nrstr(for %i in (python.exe) do @echo.%~$PATH:i);
x "&command >> &pypath"; run;