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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.