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
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
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
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.
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
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
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);
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.