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;

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 463 views
  • 2 likes
  • 3 in conversation