Hello everybody,
I know that following code works for sending an e-mail, however I want to put error rows which starts with ERROR: from my log into the body of this e-mail. And I also want to attach the full log to the attachment of the mail. I think I can make it with the ATTACH statement. But the main point is sending error rows into mail's body.
FILENAME MYMAIL EMAIL;
DATA _NULL_;
FILE MYMAIL
TO="tarik.birinci@ozu.edu.tr"
SUBJECT="%upcase(&SYSHOSTNAME) INFO";
PUT " Hello";
RUN;
I prepared a log for you and it is in the attachment. If this kind of log file occurs, then I want to see the mail as below.
My desired e-mail output as below. I will be glad if somebody help me about this issue.
Thank you,
Hey, Tarik! How about trying something like this:
/* Set up a filreref pointing to the log file */
filename readme "&filepath/sample_log.txt";
DATA _NULL_;
/* If an error is never found, we don't want anything to happen */
/* ErrorFound is a flag to remember if one has been found or not*/
retain ErrorFound 0;
infile readme;
input;
if find(_infile_,"ERROR") then do;
/* There is an ERROR message startinin this line of the log */
if not ErrorFound then do;
/* This is the first ERROR found, so set up the email */
FILE MYMAIL
TO="tarik.birinci@ozu.edu.tr"
SUBJECT="%upcase(&SYSHOSTNAME) INFO"
;
PUT " Hello";
end;
/* remember we've already found an ERROR */
ErrorFound=1;
/* Write the current LOG file line to the EMAIL file */
put _infile_;
end;
RUN;
filename mymail;
filename Readme;
May the SAS be with you!
Mark
Hey, Tarik! How about trying something like this:
/* Set up a filreref pointing to the log file */
filename readme "&filepath/sample_log.txt";
DATA _NULL_;
/* If an error is never found, we don't want anything to happen */
/* ErrorFound is a flag to remember if one has been found or not*/
retain ErrorFound 0;
infile readme;
input;
if find(_infile_,"ERROR") then do;
/* There is an ERROR message startinin this line of the log */
if not ErrorFound then do;
/* This is the first ERROR found, so set up the email */
FILE MYMAIL
TO="tarik.birinci@ozu.edu.tr"
SUBJECT="%upcase(&SYSHOSTNAME) INFO"
;
PUT " Hello";
end;
/* remember we've already found an ERROR */
ErrorFound=1;
/* Write the current LOG file line to the EMAIL file */
put _infile_;
end;
RUN;
filename mymail;
filename Readme;
May the SAS be with you!
Mark
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.