DATA Step, Macro, Functions and more

Need help sending text messages from data step

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 92
Accepted Solution

Need help sending text messages from data step

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


Accepted Solutions
Solution
‎07-29-2013 07:51 AM
Super User
Super User
Posts: 6,500

Re: Need help sending text messages from data step

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


All Replies
Solution
‎07-29-2013 07:51 AM
Super User
Super User
Posts: 6,500

Re: Need help sending text messages from data step

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;

Frequent Contributor
Posts: 92

Re: Need help sending text messages from data step

Tom,

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

Regards,

Bill

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 267 views
  • 0 likes
  • 2 in conversation