I am not sure what is wrong with the code. I want to check whether the file exist in the directory. and if it exists then just write it to the log, else send an email.
It is sending an email to be whether the file is present or not. If the file is present, it is sending an email without the body part. If not present, it is going through the loop. What is that I am missing here?
filename mailbox email 'sashelp@outlook.com" subject: missing file
data _null_;
Check= %sysfunc(fileexist(C:temp/test.csv));
if Check=0 then do;
file mailbox;
PUT "Hello,";
PUT "Please check the directory. The file is missing.";
PUT "Thanks.";
end;
else if Check=1 then do;
put "Note: File Exists: " ;
end;
Run;
Thanks
Dev Lama
You almost never need %sysfunc inside a data step. The purpose of %sysfunc is to call a data step Function in macro code outside of a data step.
So
Check= fileexist(C:temp/test.csv);
Move the file statement out of the IF condition? Though I didn't think it was a conditional statement (ie executed regardless of where it is). Maybe I don't understand your problem though.
You almost never need %sysfunc inside a data step. The purpose of %sysfunc is to call a data step Function in macro code outside of a data step.
So
Check= fileexist(C:temp/test.csv);
The logic that I am trying to implement is that when the file exist in that folder, do not send the email, but if the file does not exist please send the email.
Even when the file is present, the email is getting triggered.
Thanks
Dev Lama
Hi Dev,
your code seems fine, but few changes could help you get the expected email.
please try the below code which I modified taking your code.
filename mailbox email to='sashelp@outlook.com' subject= 'missing file';
data _null_;
Check=fileexist('C:temp/test.csv');
if Check=0 then do;
file mailbox;
PUT "Hello,";
PUT "Please check the directory. The file is missing.";
PUT "Thanks.";
end;
else if Check=1 then do;
put "Note: File Exists: " ;
end;
Run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.