www.sas.com > SAS UK > In the Know Homepage Search | Contact Us     
SAS UK Newsletter Banner SAS - The power to know(tm)  

Sending a Customised Email Depending on the Results of Other SAS Jobs

Do you have jobs running over night/early morning? Do you need to know immediately if when running one job, the balance in this agrees with the balance in another? Would it save you time being able to e-mail the results immediately, after checking to see if the two balances agree or alert someone if an error has occurred?

The following code allows an e-mail to be sent only if the variable 'amt' equals the macro variable '&all_tot' created earlier. If they don't balance, then an e-mail can be sent to alert an individual who is able to investigate why the figures do not agree. This principle is used to establish whether further jobs should run. For instance, if the amount 'amt' in the Brands dataset doesn't balance to the macro variable 'all_tot', then due to possible data errors, you may not wish further jobs to read in the datasets created by this job, until the imbalance has been investigated.

 

/* Code to generate the Amt field */

data brands;
input Brd $ Amt comma15.2 DTE date9. Vol $;
format Amt comma15.2 dte date9.;
cards;
Halifax 123,456,789.98 20Jul2006 1,234 
run;

/* Code to create the all_tot macro variable */

%let all_tot=123456789.98;

/* Check to see if they match */

data _null_;
	set Brands (keep = amt);
	if amt eq &all_tot then check = 0;
		else check = 1;

	check=(trim(left(check)));
		call symput('check', check);
run;

%macro chk;
%if &check = 0 %then %do;

/* E-Mail Code generated when the amounts balance */

data _null_;
filename ch_error email ("sukxxx@suk.sas.com")	
subject="ABC Report" attach=("d:\temp\file.xls");
run;
data _null_;
	file ch_error;
	put "Please find attached today's abc report.";
run;
%end;

%if &check = 1 %then %do;

/* E-Mail Code generated when the amounts do not balance */

data _null_;
filename ch_error email ("sukxxx@suk.sas.com") 
subject="Error - Check Report Balances" attach=("d:\temp\file.xls");
run;
data _null_;
	file ch_error;
	put "Check abc report, as an imbalance has occurred with def report."; 
run; 
%end; %

mend chk; 

%chk;