BookmarkSubscribeRSS Feed
tekish
Quartz | Level 8

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;

 

 

1 REPLY 1
Astounding
PROC Star

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.

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
  • 1 reply
  • 616 views
  • 0 likes
  • 2 in conversation