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

Hello,

I recently learned how to send emails/texts with SAS, and now I'm trying to put that knowledge to use in a data step.  Basically, I want to send myself a text mesaage with a list of CustomerIDs that have errors.  I have code that checks for errors and want to receive a text only when new CustomerIDs appear in the "error" data set.  Here's the code that I'm currently using:

Top of program:

options emailsys=smtp emailauthprotocol=login emailid="xxxxxx@aol.com" emailpw="xxxxxxxx"

emailhost=smtp.aol.com  emailport=587;

Code within macro:

DATA NEW_ERRORS;

MERGE OUT.KNOWN_ERRORS (IN=IN1) ERRORS (IN=IN2);

BY CUST_ID;

IF IN2 & NOT IN1 THEN DO;

     OUTPUT NEW_ERRORS;

     filename mymail email "xxxxxxxx@txt.att.net" subject="CustomerIDs with potential errors" lrecl=256;

     file mymail;

     put 'list of CustomerIDs with errors separated by commas or spaces.';  *Still need to figure out this part!;

END;

RUN;

proc append base=OUT.KNOWN_ERRORS data=NEW_ERRORS FORCE;

proc sort data = OUT.KNOWN_ERRORS; BY CUST_ID; RUN; *NEED TO SORT DATA FOR SUBSEQUENT MERGES;

What I'm attempting to with the above is take the list of errors over all CustomerIDs (ERRORS) and compare them with the currently known list of CustomerIDs with errors (OUT.KNOWN_ERRORS).  If there's a new set of CustomerIDs with an errors I want to 1) receive a text message with only that list of CustomerIDs (new errors) and 2) add those CustomerIDs to the currently known list of errors (OUT.KNOWN_ERRORS).  This way when the code is run again, I won't receive another text with the same list of CustomerIDs.  Note code works fine in terms of identifying and adding only the new errors to the known list of errors.  The issue I'm having is debugging the text message part.  When I run the code with no new CustomerIDs added to the list, I get constantly bombarded with text messages.  Therefore my DO statement isn't firing the text message code appropriately.  Does anyone have any suggestion as to what I'm doing wrong?  Am I trying to do  too much in one data step?  Also, does anyone know how to include the list of new CustomerIDs in the body of my text?  I was hoping to do this in a list format with each CustomerID separated by commas or spaces.  How would I create such a list?  As output to my log?  Or do I need to create some sort of macro variable that'll be used in an ODS statement?

Any help or advice would be greatly appreciated.  Thank you very much!

-Bill

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why not just split the email as a separate step from the merge?

You could then use macro logic or other code generation methods to only send an email when new items are found.

%let anynew=0;

data new_errors;

  merge out.known_errors (in=in1) errors (in=in2);

  by cust_id;

  if not in1 ;

  call symput('anynew','1');

run;


%if &anynew %then %do;

  filename mymail email "xxxxxxxx@txt.att.net"

     subject="CustomerIDs with potential errors" lrecl=256

  ;

  data _null_;

     set new_errors ;

     file mymail dsd ;

     put custid @@;

  run;

%end;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Why not just split the email as a separate step from the merge?

You could then use macro logic or other code generation methods to only send an email when new items are found.

%let anynew=0;

data new_errors;

  merge out.known_errors (in=in1) errors (in=in2);

  by cust_id;

  if not in1 ;

  call symput('anynew','1');

run;


%if &anynew %then %do;

  filename mymail email "xxxxxxxx@txt.att.net"

     subject="CustomerIDs with potential errors" lrecl=256

  ;

  data _null_;

     set new_errors ;

     file mymail dsd ;

     put custid @@;

  run;

%end;

BillJones
Calcite | Level 5

Tom,

My apologies for the delayed response.  Thanks so much for the above.  Your solution worked perfectly!!!

Regards,

Bill

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1376 views
  • 0 likes
  • 2 in conversation