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

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!!

1 ACCEPTED SOLUTION

Accepted Solutions
DaveHorne
SAS Employee

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

2 REPLIES 2
DaveHorne
SAS Employee

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;
Agogo
Calcite | Level 5

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

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 385 views
  • 0 likes
  • 2 in conversation