BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LisaXu
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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";

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

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";
LisaXu
Obsidian | Level 7

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!!

LisaXu
Obsidian | Level 7

Impressive, Tom! You are right to the point! It worked! Really appreciate your help!!

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 933 views
  • 0 likes
  • 2 in conversation