I have created a batch (.bat) file to run my SAS 9.4 program. When I manually run the batch file, the program runs perfectly fine. However, when I schedule the batch file to run using the windows task scheduler, the program doesn't run properly. It seems to get hung up when I start to use relative paths in my libname statements.
Here is the piece of my SAS code that is having trouble when run as a scheduled task:
data _NULL_;
%let Prog = %sysfunc(getoption(sysin));
run;
proc sql noprint;
select tranwrd(xpath,"\&prog","") into :source
from dictionary.extfiles
where index(xpath,"&prog") > 0;
quit;
X "cd &source";
libname Derived "..\Datasets";
When I run the SAS program or the batch file manually, the relative paths work great. But for some reason when the batch file is run as a scheduled task, I get a note in the log saying "Library DERIVED does not exist." Does anyone know why the relative paths aren't working when run as a scheduled task? I'd really prefer not to have to change every relative path to absolute paths if possible.
Your "desktop" environment differs subtly from your "batch" environment (current working directory). Therefore always use absolute pathnames.
The same is true for other platforms (UNIX etc)
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.