Dynamic E-mail

Accepted Solution Solved
Reply
Contributor
Posts: 64
Accepted Solution

Dynamic E-mail

Hi there,

 

I am trying to setup a dynamic e-mail.

So in my table work.W4EHPWV I will have various info relating to particular users.

So I could have 5 different e-mails on 5 different lines.

 

Name       E-mail                      Info

Test1        mail@test1.com      Hi

Test2        mail@test2.com      Whats up

 

I can get this sending sigularly to the email below no problem, but what I would like is for the e-mail to be a variable and send on the info relating to the email address.

 

I hope this makes sense, see below code to date.

 

filename temp email to="mail@test1.com"
type="text/html"
subject="TEST Daily Alert List";
ods html file=temp;
proc print data=work.W4EHPWV;
run;
ods html close;

 

 

Thanks

Aidan


Accepted Solutions
Solution
‎01-20-2017 10:07 AM
Super Contributor
Posts: 474

Re: Dynamic E-mail

Yes.

 

Sorry my miskate, I made some changes to the ods file statement so I could test it here.

 

Replace:

 

ods html file='location\xpto.txt';

 

with:

 

ods html file=temp;

 

 

Daniel Santos @ www.cgd.pt

View solution in original post


All Replies
Super Contributor
Posts: 474

Re: Dynamic E-mail

[ Edited ]

Hi.

 

Use a macro to cycle trhough, something like this:

 

* send mail from DATA;
%macro mailit(DATA);

%let NOBS=0;
* get emails from DATA;
proc sql noprint;
select EMAIL into :EMAIL1- from &DATA;
select count(*) into :EMAILN from &DATA;
quit;

* cycle through emails;
%do I=1 %to &EMAILN;
 
filename temp email to="&&&EMAIL&I"
type="text/html"
subject="TEST Daily Alert List";
ods html file='d:\temp\xpto.txt';
proc print data=&DATA;
var INFO;
where EMAIL="&&&EMAIL&I";
run;
ods html close;

%end;

%mend mailit;

%mailit(W4EHPWV);

 

So first the emails are loaded into n macro variables (EMAILn) and a cycle is performed for each.

 

Hope it helps.

 

Daniel Santos @ www.cgd.pt

Contributor
Posts: 64

Re: Dynamic E-mail

Posted in reply to DanielSantos

Thanks for your reply, I have tried this solution but am getting the below error.

ANy ideas?

 

The e-mail address can be up to 255 long, should I substr() this?

 

ERROR: Invalid macro parameter name &. It should be a valid SAS identifier no longer than 32 characters.

Super Contributor
Posts: 474

Re: Dynamic E-mail

Hmmm. It shouldn't.

 

I've tested the code with this sample, and works as expected:

 

data W4EHPWV;
input @1 TEST $13. @14 EMAIL $20. @34 INFO $8.;
datalines;
Test1        mail@test1.com      Hi      
Test2        mail@test2.com      Whats up
run;

 

What's the SAS version you are running there?

 

Daniel Santo @ www.cgd.pt

Contributor
Posts: 64

Re: Dynamic E-mail

Posted in reply to DanielSantos
Version=4.901

Maybe if I try trimming the email to the same length as what you have it could work, let me try that.

Super Contributor
Posts: 474

Re: Dynamic E-mail

Hi.

 

Shouldn't be necessary.

 

v4.901? Are you running the code through SAS Data Integration Studio?

 

Anyway, run the following in a code window:

 

proc product_status; run;

 

It will list the your SAS/Base version, which was what I was asking for.

 

Daniel Santos @ www.cgd.pt

 

 

 

 

Super Contributor
Posts: 474

Re: Dynamic E-mail

Posted in reply to DanielSantos

Well yes.

 

no & on DATA there, check the code I have posted.

 

Daniel Santos @ www.cgd.pt

Contributor
Posts: 64

Re: Dynamic E-mail

Posted in reply to DanielSantos

My table just has a column called ALERT and EMAIL

 

The code is now executing without errors, but no e-mail is sending.

Code changes below, I have just removed the lcoation info;

 

 

* send mail from DATA;
%macro mailit(DATA);

%let NOBS=0;
* get emails from DATA;
proc sql noprint;
select EMAIL into :EMAIL1- from &DATA;
select count(*) into :EMAILN from &DATA;
quit;

* cycle through emails;
%do I=1 %to &EMAILN;

filename temp email to="&&&EMAIL&I"
type="text/html"
subject="TEST Daily Alert List";
ods html file='location\xpto.txt';
proc print data=&DATA;
var ALERT;
where EMAIL="&&&EMAIL&I";
run;
ods html close;

%end;

%mend mailit;

%mailit(W9QRSD);

Solution
‎01-20-2017 10:07 AM
Super Contributor
Posts: 474

Re: Dynamic E-mail

Yes.

 

Sorry my miskate, I made some changes to the ods file statement so I could test it here.

 

Replace:

 

ods html file='location\xpto.txt';

 

with:

 

ods html file=temp;

 

 

Daniel Santos @ www.cgd.pt

Contributor
Posts: 64

Re: Dynamic E-mail

Posted in reply to DanielSantos
Yes that is working now, if I have 15 rows of data it is sending 15 mails for each. Is there a way to limit this to 1 e-mail per 15 rows.

I appreciate your patience and help so thank you
Contributor
Posts: 64

Re: Dynamic E-mail

Posted in reply to DanielSantos
Seems to be the line &DATA, should this be altered in any way? The source table is work.W9QRSD

2431 %macro mailit(&DATA);
ERROR: Invalid macro parameter name &. It should be a valid SAS identifier no longer than 32 characters.
ERROR: A dummy macro will be compiled.
☑ This topic is solved.

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

Discussion stats
  • 10 replies
  • 235 views
  • 3 likes
  • 2 in conversation