Hi guys!
I am using the following script to send e-mails:
Filename OK&id
Email From = ("&SENDER")
Sender = ("&SENDER")
To = ("&RECEIVER" )
Subject = "&SUBJECT"
ATTACH = ("&AttachmentPath")
;
data _null_;
file OK&id;
PUT "&Content"
//;
run;
In the log file I see the following:
NOTE: 3 records were written to the file OK4.
The minimum record length was 0.
The maximum record length was 19.
I want to execute a subsequent data step which is based on if recrods were written to the file because if the mail part fails there's no records written to the file (or at least indicated in the log). Is there a way for me to check how many records are in the file OK4 in my code?
You can test if the file exists BEFORE trying to attach it to the email.
%if %sysfunc(fileexist("&AttachmentPath")) %then %do;
... send email ...
%end;
%else %do;
... write note ...
%end;
You can use
proc printto log="<log file path and name>.log"; run;
*your code written here;
proc printto; run;
data _null_;
infile "<log file path and name>.log";
input line $100.;
if index(line,"Records") then do;
/* extract number of records */
end;
run;
You need to post more details of the code you are running, the step you have posted imho can't write 0 obs.
Well, my question is related to this specific part and I don't have a code afterwards (that's what I'm asking for). If the attachment is correct it will give me the log that I posted. Let's say the attachment file is deleted by a user, then it will print the following in the log:
You can test if the file exists BEFORE trying to attach it to the email.
%if %sysfunc(fileexist("&AttachmentPath")) %then %do;
... send email ...
%end;
%else %do;
... write note ...
%end;
@sasnewbiexx wrote:
Well, my question is related to this specific part and I don't have a code afterwards (that's what I'm asking for). If the attachment is correct it will give me the log that I posted. Let's say the attachment file is deleted by a user, then it will print the following in the log:
NOTE: The file OK4 is:
E-Mail Access DeviceERROR: Error opening attachment file D:\\TestAttc.xlsx.
ERROR: Physical file does not exist, D:\\TestAttc.xlsx.So my overall goal is to add code and try and check if records have been written or not to the OK4 file.
Please post the full log.
It is not clear what you have run.
Pay attention OK4 and the log file created by proc printto are different files.
Running the code as you first posted should crate a file probably like
<sender mail> <recipient mail> <contents given> <space line as a result of PUT ...//>
NOTE: Remote submit to MYNODE commencing.
247 Filename OK&id Email From = ("&SENDER") Sender = ("&SENDER") To = ("&RECEIVER" ) Subject =
247! "&SUBJECT" ;
248 data _null_;
249 file OK&id;
250 PUT "&Content" //;
251 run;
NOTE: The file OK4 is:
E-Mail Access Device
Message sent
To: "email@email.com"
Cc:
Bcc:
Subject: TestExternal
Attachments:
NOTE: 3 records were written to the file OK4.
The minimum record length was 0.
The maximum record length was 19.
NOTE: DATA statement used (Total process time):
real time 0.18 seconds
cpu time 0.00 seconds
This is the log. Can this file OK4 be saved somewhere (in a library) or be read from a the code?
@sasnewbiexx wrote:
Well, my question is related to this specific part and I don't have a code afterwards (that's what I'm asking for). If the attachment is correct it will give me the log that I posted. Let's say the attachment file is deleted by a user, then it will print the following in the log:
NOTE: The file OK4 is:
E-Mail Access DeviceERROR: Error opening attachment file D:\\TestAttc.xlsx.
ERROR: Physical file does not exist, D:\\TestAttc.xlsx.So my overall goal is to add code and try and check if records have been written or not to the OK4 file.
So you don't need to run code after sending the mail, you need to change the code, so that the mail is only send, if the attachment exists. @Tom posted a solution for this problem.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.