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
SAS Super FREQ

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
SAS Super FREQ

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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1 reply
  • 974 views
  • 0 likes
  • 2 in conversation