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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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