BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aidan
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
DanielSantos
Barite | Level 11

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

10 REPLIES 10
DanielSantos
Barite | Level 11

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

Aidan
Quartz | Level 8

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.

DanielSantos
Barite | Level 11

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

Aidan
Quartz | Level 8
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.

DanielSantos
Barite | Level 11

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

 

 

 

 

DanielSantos
Barite | Level 11

Well yes.

 

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

 

Daniel Santos @ www.cgd.pt

Aidan
Quartz | Level 8

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);

DanielSantos
Barite | Level 11

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

Aidan
Quartz | Level 8
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
Aidan
Quartz | Level 8
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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 10 replies
  • 1640 views
  • 3 likes
  • 2 in conversation