All,
Need to receive an email alert if one of the row missing.
if we look into below code.
e.txt is missing from test table so need to get an email with e.txt in the body.
done the proc compare but not sure how to read that missing row into a table and send that missing row to an email.
data test;
infile cards;
input filename $40.;
cards;
a.txt
c.txt
b.txt
d.txt
;
run;
proc sort data=test;
by filename;
run;
data test1;
infile cards;
input filename $40.;
cards;
a.txt
b.txt
d.txt
e.txt
c.txt
;
run;
proc sort data=test1;
by filename;
run;
proc compare base=test compare=test1 LISTCOMPOBS;
run;
Like this?
filename EMAIL email .... ;
data EMAIL;
merge TEST (in=A) TEST1(in=B) ;
by FILENAME;
if ^(A & B);
call execute('data _null_; set EMAIL; file EMAIL; put FILENAME; run;');
run;
Import your data into sas and compare number of observations before any sort or datasets compare:
%let need_mail = NO;
data _null_;
dsid = open('work.test');
if dsid then nobs1 = attrn(dsid,'nobs');
dsid = close(dsid);
dsid = open('work.test1');
if dsid then nobs2 = attrn(dsid,'nobs');
dsid = close(dsid);
if nobs1 ne nobs2 then
call symput('need_mail','YES');
run;
%macro send_mail(send_flag);
%if &send_flag = YES %then %do;
/* send non matching mail code */
.........
%end;
%mend send_mail;
%send_mail(&need_mail);
Like this?
filename EMAIL email .... ;
data EMAIL;
merge TEST (in=A) TEST1(in=B) ;
by FILENAME;
if ^(A & B);
call execute('data _null_; set EMAIL; file EMAIL; put FILENAME; run;');
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.