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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

View solution in original post

4 REPLIES 4
Reeza
Super User

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. 

ballardw
Super User

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

devnand
Obsidian | Level 7

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

Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag

SAS Innovate 2025: Register Now

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!

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
  • 4 replies
  • 1414 views
  • 0 likes
  • 4 in conversation