I need to schedule a daily SAS program run to check existence of a file and process it. Somehow, when I run the program in PC SAS , it can get the correct results. But when I use the Windows Task Scheduler to run it, it comes back "File does not exist". Same program. Anyone has any idea what could be wrong? Thanks so much!!
%let FileRef="R:\&filename";
%put &FileRef;
/**"R:\Account_2021-02-11.txt"**/
%let FR=%sysfunc(dequote(&FileRef));
%put &FR;
/**R:\Account_2021-02-11.txt**/
%macro CheckFile;
%if %sysfunc(fileexist(&FR)) %then %do;
data aa ;
infile &FileRef firstobs=2;
;
input ............
run;
%end;
%else %put The file &FileRef does not exist. ;
%mend;
What is R: ? Most likely you have mapped some network share to that drive letter as you probably do not have that many physical hard disks on your computer.
It seems likely that the scheduled job is running under a different user or at least setting up the Windows environment in a different way such that the R drive is not mapped (or if a different user then it does not have permission to see the requested file or the folder that holds it).
I would first try using UNC instead of mapped drive. So if R: is mapped to \\some-server\some-share then change the code to:
%let FileRef="\\some-server\some-share\&filename";
What is R: ? Most likely you have mapped some network share to that drive letter as you probably do not have that many physical hard disks on your computer.
It seems likely that the scheduled job is running under a different user or at least setting up the Windows environment in a different way such that the R drive is not mapped (or if a different user then it does not have permission to see the requested file or the folder that holds it).
I would first try using UNC instead of mapped drive. So if R: is mapped to \\some-server\some-share then change the code to:
%let FileRef="\\some-server\some-share\&filename";
Thanks so much for your quick reply, Tom! Yes, the R drive is what I mapped to save the long path...I'll fix that and see...Thanks again!!
Impressive, Tom! You are right to the point! It worked! Really appreciate your help!!
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!
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.