BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tarikbirinci1
Calcite | Level 5

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.

 

sample_mail.png

Thank you,

1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
Ammonite | Level 13

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

Check out my Jedi SAS Tricks for SAS Users

View solution in original post

1 REPLY 1
SASJedi
Ammonite | Level 13

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

Check out my Jedi SAS Tricks for SAS Users

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1493 views
  • 0 likes
  • 2 in conversation