DATA Step, Macro, Functions and more

create a macro for undeliverable email

Reply
Contributor
Posts: 67

create a macro for undeliverable email

Dear expert;

 

I want to create two undeliverable email template(ale and female). How do I create a macro on the subject field.

here is my sample codes.

 

data class;

set sashelp.class;

length email $50;

if sex="M" then flag=1;

else flag=0;

if name="Alfred" then email="Alfred.com";

else if name="Alice" then email="Alice.com";

else if name="Barbara" then email="Barbara.com";

else if name="Carol" then email="Carol.com";

else if name="Henry" then email="Henry.com";

else if name="James" then email="James.com";

else if name="Jane" then email="Jane.com";

else if name="Janet" then email="Janet.com";

else if name="Janet" then email="Janet.com";

else if name="Janet" then email="Janet.com";

else if name="Jeffrey" then email="Jeffrey.com";

else if name="John" then email="John.com";

else if name="Joyce" then email="Joyce.com";

else if name="Judy" then email="Judy.com";

else if name="Judy" then email="Judy.com";

else if name="Louise" then email="Louise.com";

else if name="Mary" then email="Mary.com";

else if name="Philip" then email="Philip.com";

else if name="Mary" then email="Mary.com";

else if name="Robert" then email="Robert.com";

else if name="Ronald" then email="Ronald.com";

else if name="Thomas" then email="Thomas.com";

else if name="William" then email="William.com";

run;

proc sort data=class;

by email;

run;

Data _null_;

set class;

by email;

if flag=1 then call symputx('Male','1');

run;

%put male=&Male;

 

 

%MACRO B_EMAIL(EMAIL);

options emailsys=SMTP emailport=XX;

  

FILENAME MYMAIL EMAIL

TO = "myemailaddress@t.com"

%if &Male=1 %then %do;

SUBJECT = "Male Undeliverable Email Address"

%end;

%else %do;

SUBJECT = "FeMale Undeliverable Email Address"

%end;

CT = "TEXT/HTML"

BCC = "myemailaddress@t.com"

FROM = "myemailaddress@t.com"

SENDER = "myemailaddress@t.com"

REPLYTO = "myemailaddress@t.com"

 

DATA TEMP;

SET class;

BY email;

IF email = "&EMAIL";

 

RUN;

DATA _NULL_;

FILE MYMAIL;

SET TEMP;

%IF &TESTING = Y %THEN %DO;

EMAILADDRESS = "myemailaddress@t.com";

%END;

PUT '!EM_TO! ' EMAILADDRESS;

%if &male=1 %then %do;

PUT "Dear Mr." Name;

%end;

%else %do;

PUT "Dear Mrs." Name;

%end;

PUT "<p>";

PUT "You are receiving this email because the following respondent’s Welcome email was returned to us as undeliverable:";

PUT "<p>";

 

PUT EMAIL;

PUT "<p>";

PUT "Please correct the respondent’s email address and re-send the email";

 

 

PUT '</font></body></html>';

 

RUN;

FILENAME MYMAIL CLEAR;

%MEND B_EMAIL;

%LET TESTING = Y;

DATA _NULL_;

SET class;

BY email;

CALL EXECUTE('%B_EMAIL('||email||')');

RUN;

 

 

Super User
Posts: 6,529

Re: create a macro for undeliverable email

Mostly what you do is get rid of the macro language.  Almost all of this gets accomplished without macros at all.  Almost all.

 

Here's a starting point to get you moving in the right direction.  It's not everything you need, but it's much closer to what your final program should look like.  Your first DATA step contains:

 

if sex="M" then flag=1;

else flag=0;

 

That should be expanded to include:

 

if sex="M" then do;

   Subject=

   CT=

   BCC=

   FROM=

   SENDER=

   REPLYTO=

   SALUTATION = 'DEAR MR. ';

end;

else do;

 

etc.

 

DATA steps manipulate data.  Macro language control which data step statements should execute.  Let the DATA step do the work that it should.

Ask a Question
Discussion stats
  • 1 reply
  • 88 views
  • 0 likes
  • 2 in conversation