send an email to different mailbox base on which server I run the program on?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

send an email to different mailbox base on which server I run the program on?

have a program that runs and send an email but want to set it up so the macro that sent the email execute depending on the server (live or test) I am runing it on.

I have created 4 macros namely email,report,live_email and live_report - I call the maco %report if there is a record in the dataset else %email. The same recipient for %email and %report and another recipient for live_email and live_report.

currently it send the email to %report recipient irrespective or the server.

 


/* SETTING ENVIRONMENT */
options symbolgen mlogic;
%let env = %scan( &SYSTCPIPHOSTNAME,1,'.');

** *********************** LIVE ***************************************;;
%let live = gal;
%let liveRecipients = 'missjoe.blog@sch.com ';

************************** TEST ***************************************;;
%let test = guy;
%let testRecipients = 'joe.bloc@sch.com';



data _null_;
set cont;
if &env. eq &test. then
do;
if nobs>0 then
call execute('%report');
else call execute('%email');
end;
else if &env. eq &live. then
do;
if nobs>0 then
call execute('%live_report');
else call execute('%live_email');
end;

run;

 

 

Help please!!


Accepted Solutions
Solution
‎03-30-2017 04:59 AM
SAS Employee
Posts: 5

Re: send an email to different mailbox base on which server I run the program on?

[ Edited ]

I do something similar in many of my SAS jobs.  First a %setenv macro that determines the environment and creates settings based on live/test.  Then a single %report and %email macro (that can check the &env and perform the appropriate actions).  Lastly a single %runit macro which checks the nobs and runs either %report or %email.  The nobs check could be as simple as checking &sysnobs (or opening the data set and using the attrn function check as in the example).  Hope this helps.

 

/* SETTING ENVIRONMENT */
options symbolgen mlogic;
%global env Recipients;

%macro setenv;
   %if %substr(&SYSTCPIPHOSTNAME,1,1) = L %then %do;  /* live */
      %let env=Live;
      %let Recipients = missjoe.blog@sch.com;
   %end;

   %else %do;  /* test */
      %let env=Test;
      %let Recipients = joe.bloc@sch.com;
   %end;
%mend setenv;
%setenv;

%macro report;
  title "&env Report for &sysdate";
  proc print data=cont;
  run;
%mend report;

%macro email;
  filename mailbox email to=("&Recipients") subject="No data for env=&env";
  data _null_;
    file mailbox;
    put "No data available for &env.";
  run;
%mend email;

%macro runit;
  /* get nobs via attrn */
  data _null_;
    dsid=open('cont','I');
    nobs=attrn(dsid,'nobs');
    rc=close(dsid);
    call symput('nobs',nobs);
  run;

  %if &nobs > 0 %then %report;
  %else %email;

%mend runit;
%runit;

View solution in original post


All Replies
Solution
‎03-30-2017 04:59 AM
SAS Employee
Posts: 5

Re: send an email to different mailbox base on which server I run the program on?

[ Edited ]

I do something similar in many of my SAS jobs.  First a %setenv macro that determines the environment and creates settings based on live/test.  Then a single %report and %email macro (that can check the &env and perform the appropriate actions).  Lastly a single %runit macro which checks the nobs and runs either %report or %email.  The nobs check could be as simple as checking &sysnobs (or opening the data set and using the attrn function check as in the example).  Hope this helps.

 

/* SETTING ENVIRONMENT */
options symbolgen mlogic;
%global env Recipients;

%macro setenv;
   %if %substr(&SYSTCPIPHOSTNAME,1,1) = L %then %do;  /* live */
      %let env=Live;
      %let Recipients = missjoe.blog@sch.com;
   %end;

   %else %do;  /* test */
      %let env=Test;
      %let Recipients = joe.bloc@sch.com;
   %end;
%mend setenv;
%setenv;

%macro report;
  title "&env Report for &sysdate";
  proc print data=cont;
  run;
%mend report;

%macro email;
  filename mailbox email to=("&Recipients") subject="No data for env=&env";
  data _null_;
    file mailbox;
    put "No data available for &env.";
  run;
%mend email;

%macro runit;
  /* get nobs via attrn */
  data _null_;
    dsid=open('cont','I');
    nobs=attrn(dsid,'nobs');
    rc=close(dsid);
    call symput('nobs',nobs);
  run;

  %if &nobs > 0 %then %report;
  %else %email;

%mend runit;
%runit;
Occasional Contributor
Posts: 9

Re: send an email to different mailbox base on which server I run the program on?

Thanks very much DaveHorne, just got to the office would test shortly and give you feedback.

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 112 views
  • 0 likes
  • 2 in conversation