Posted By

ccw on 03/29/12


Tagged

notification etl sas


Versions (?)

[SAS] ETL Email Noticiation


 / Published in: SAS
 

An example to notify users with ETL job status

  1. %let INFO_ADDR_LENGTH=1;
  2.  
  3. %let DEBUG_ADDR_LENGTH=1;
  4.  
  5. %let DB_ADDR_LENGTH=1;
  6.  
  7. %let DEBUG_FLAG=N;
  8.  
  9. options mprint;
  10.  
  11. %macro etls_sendEmail(address=, subject=, message=);
  12.  
  13. filename sendMail email "&address" subject="SAS ETL Notice - &subject";
  14.  
  15. %local etls_syntaxcheck;
  16. %let etls_syntaxcheck = %sysfunc(getoption(syntaxcheck));
  17. /* Turn off syntaxcheck option to perform following steps */
  18. options nosyntaxcheck;
  19.  
  20. data _null_;
  21. file sendMail;
  22. dttm = put(datetime(),nldatm.);
  23. put dttm "&message.";
  24. run;
  25.  
  26. /* Reset syntaxcheck option to previous setting */
  27. options &etls_syntaxcheck;
  28. %mend etls_sendEmail;
  29.  
  30. %macro etls_sendAllEmails(type=INFO,subject=, message=);
  31. %DO I = 1 %TO &&&type._ADDR_LENGTH;
  32. %PUT Sending email to &&&type._ADDR_&I;
  33. %etls_sendEmail(address = &&&type._ADDR_&I,
  34. subject = &subject,
  35. message = &message);
  36. %END;
  37. %mend etls_sendAllEmails;
  38.  
  39. %macro etls_jobRCChk(type=DEBUG, subject=Job Status [&etls_jobName]);
  40. %if (&DEBUG_FLAG eq Y) %then %do;
  41. %if (&job_rc eq 0) %then
  42. %do;
  43. %etls_sendAllEmails(type = &type,
  44. subject = &subject,
  45. message = Success);
  46. %end;
  47. %else %if (&job_rc ge 5) %then
  48. %do;
  49. %etls_sendAllEmails(type = &type,
  50. subject = &subject,
  51. message = Fail);
  52. %end;
  53. %end;
  54. %mend etls_jobRCChk;
  55.  
  56. %macro etls_flowNotice(type=S, flow=CMDM);
  57. %if (&type eq E) %then
  58. %do;
  59. %etls_sendAllEmails(subject = Process Status,
  60. message = &flow Batch Job Completed Successfully);
  61. %end;
  62. %else
  63. %do;
  64. %etls_sendAllEmails(subject = Process Status,
  65. message = &flow Batch Job Started);
  66. %end;
  67. %mend etls_flowNotice;
  68.  
  69. %macro etls_dataValidChk(tblSRC=,cntSRC=,tblDist=,cntDist=);
  70. %if (&cntSRC ge 0 and &cntDist ge 0) %then
  71. %do;
  72. %etls_sendAllEmails(type = INFO,
  73. subject = Data Loading Checkpoint,
  74. message = Loading [&cntSRC] records from &tblSRC and output [&cntDist] records into &tblDist);
  75. %end;
  76. %mend etls_dataValidChk;

Report this snippet  

You need to login to post a comment.