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

Hello,

I'm an inexperienced user of SAS Data Integration Studio.


I would like to receive an e-mail information about the job status. Using "Status Handling" and action "Send Email" (from job options) is not satisfying to me. First of all - (propably?) i can't attach log to this e-mail (maybe there is another option for this job?).


In SAS Enterprise Guide I developed and tested code for sending email with log in attach and some useful informations (datetime, list of errors) in mail body:

%let mail = "test@test.com";
%let path_error = /home/ ... .log;

filename msg email
 to =           (&maile)
 subject =      "SAS Message Test"
 attach =       "&path_error.";

data _null_;
 dttm = put(datetime(),nldatm.);

 infile "&path_error.";
 input;

 file msg;
 if _n_ = 1 then do;
    put "Date time: " dttm;
    put;
    put "Full log in attach.";
    put "There are some ERRORs and WARNINGs:";
    put;
    end;
 if substr(_infile_,1,5) = "ERROR" then 
    put _infile_;
 if substr(_infile_,1,7) = "WARNING" then 
    put _infile_;
run;

This code works fine - I get complete mail with list of errors and warnings. In log from Enterprise Guide I can see:

NOTE: 268 records were read from the infile "[...].log"

But how to implement this code (especially reading by infile statement) in DIS?

I have modified the job options:

  1. Precode - puts the log into an external file; log name contains jobname and datetime:
%let path = /home/[...]/log_&etls_jobName._%sysfunc(datetime(), datetime.).log; 
proc printto log="&path.";
run;
  1. Postcode - I used code from Enterprise Guide:
%let address = "test@test.com";
%let message = problems with &etls_jobName;

         filename sendMail email 
                to=         (&address) 
                subject=        "ETL Process problem: &etls_jobName." 
                attach=     "&path."; 

            options nosyntaxcheck;  

         data _null_; 
            dttm = put(datetime(),nldatm.);

                infile "&path.";
                input;

                file sendMail; 
                 if _n_ = 1 then do;
                    put "Date time: " dttm;
                    put;
                    put "Full log in attach.";
                    put "There are some ERRORs and WARNINGs:";
                    put;
                    end;
                 if substr(_infile_,1,5) = "ERROR" then 
                    put _infile_;
                 if substr(_infile_,1,7) = "WARNING" then 
                    put _infile_;
         run; 

In effect I get e-mail with log in attach, but empty body. In attached log I can see:

NOTE: 0 records were read from the infile 

I've got some questions:

  1. Why 0 records???
  2. When I delete input; statement from Postcode and run job I get e-mail with "Date time / Full log in attach / There are some ERRORs and WARNINGs" in body. Why they are deleted where input works in code?
  3. E-mail is not sending without options nosyntaxcheck; in code. Why?

Thanks for the answers. Regards, Michał

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Hi,

 

The answer to your third question may resolve the first two as well.

 

If there is an error in your SAS session and SAS enters syntaxcheck mode, no later data will be processed, and this would prevent your data _null_ step from reading in the data via the INPUT statement.


I take a similar log emailing approach in my DI jobs.  Before your log scanning / emailing code at the end, you can add:

 

  options obs=max replace NoSyntaxCheck;

This basically recovers from syntaxcheck mode, and tells SAS to go back to executing any following data steps.

 

--Q.

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

2 REPLIES 2
Quentin
Super User

Hi,

 

The answer to your third question may resolve the first two as well.

 

If there is an error in your SAS session and SAS enters syntaxcheck mode, no later data will be processed, and this would prevent your data _null_ step from reading in the data via the INPUT statement.


I take a similar log emailing approach in my DI jobs.  Before your log scanning / emailing code at the end, you can add:

 

  options obs=max replace NoSyntaxCheck;

This basically recovers from syntaxcheck mode, and tells SAS to go back to executing any following data steps.

 

--Q.

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
MichalRa
Fluorite | Level 6
Hi Quentin,

thank you! The code is working fine now.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 567 views
  • 2 likes
  • 2 in conversation