Return to Snippet

Revision: 56464
at March 29, 2012 16:13 by ccw


Initial Code
%let [email protected];
%let INFO_ADDR_LENGTH=1;

%let [email protected];
%let DEBUG_ADDR_LENGTH=1;

%let [email protected];
%let DB_ADDR_LENGTH=1;

%let DEBUG_FLAG=N;

options mprint;

%macro etls_sendEmail(address=, subject=, message=); 
      
    filename sendMail email "&address" subject="SAS ETL Notice - &subject"; 
      
    %local etls_syntaxcheck; 
    %let etls_syntaxcheck = %sysfunc(getoption(syntaxcheck)); 
    /* Turn off syntaxcheck option to perform following steps  */ 
    options nosyntaxcheck;
      
    data _null_; 
        file sendMail; 
        dttm = put(datetime(),nldatm.); 
        put dttm "&message."; 
    run; 
      
    /* Reset syntaxcheck option to previous setting  */ 
    options &etls_syntaxcheck; 
%mend etls_sendEmail;

%macro etls_sendAllEmails(type=INFO,subject=, message=);
  %DO I = 1 %TO &&&type._ADDR_LENGTH; 
    %PUT Sending email to &&&type._ADDR_&I;
	%etls_sendEmail(address = &&&type._ADDR_&I,
	                subject = &subject,
		        message = &message);
  %END;
%mend etls_sendAllEmails;

%macro etls_jobRCChk(type=DEBUG, subject=Job Status [&etls_jobName]); 
   %if (&DEBUG_FLAG eq Y) %then %do;
   %if (&job_rc eq 0) %then
   %do; 
      %etls_sendAllEmails(type = &type,
	                  subject = &subject, 
	                  message = Success); 
   %end; 
   %else %if (&job_rc ge 5) %then
   %do; 
      %etls_sendAllEmails(type = &type,
	                  subject = &subject, 
	                  message = Fail);
   %end;
   %end;
%mend etls_jobRCChk; 

%macro etls_flowNotice(type=S, flow=CMDM);
   %if (&type eq E) %then
   %do; 
      %etls_sendAllEmails(subject = Process Status, 
	                  message = &flow Batch Job Completed Successfully); 
   %end; 
   %else
   %do; 
      %etls_sendAllEmails(subject = Process Status, 
	                  message = &flow Batch Job Started);
   %end;
%mend etls_flowNotice;

%macro etls_dataValidChk(tblSRC=,cntSRC=,tblDist=,cntDist=);
  %if (&cntSRC ge 0 and &cntDist ge 0) %then
  %do;
      %etls_sendAllEmails(type = INFO,
                          subject = Data Loading Checkpoint,
                          message = Loading [&cntSRC] records from &tblSRC and output [&cntDist] records into &tblDist);
  %end;
%mend  etls_dataValidChk;

Initial URL


Initial Description
An example to notify users with ETL job status

Initial Title
[SAS] ETL Email Noticiation

Initial Tags


Initial Language
SAS