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

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;
               

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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;

 

View solution in original post

2 REPLIES 2
Shmuel
Garnet | Level 18

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);

 

ChrisNZ
Tourmaline | Level 20

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;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 724 views
  • 2 likes
  • 3 in conversation