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!!
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;
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;
Thanks very much DaveHorne, just got to the office would test shortly and give you feedback.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.