DATA Step, Macro, Functions and more

About email from SAS

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

About email from SAS

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

 


Accepted Solutions
Solution
‎11-10-2016 09:51 PM
Super User
Posts: 10,500

Re: About email from SAS

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


All Replies
Super User
Posts: 17,831

Re: About email from SAS

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. 

Solution
‎11-10-2016 09:51 PM
Super User
Posts: 10,500

Re: About email from SAS

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

Contributor
Posts: 39

Re: About email from SAS

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

Trusted Advisor
Posts: 1,129

Re: About email from SAS

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
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 224 views
  • 0 likes
  • 4 in conversation