Hi there,
I have the below code, which works fine to dynamically e-mail a distribution list I have dynamically each day.
How would I go about adding a new condition to factor in varying people to CC on the e-mail.
I have tried a few things however keep failing in my attempts. I tried adding select distinct EMAILCC into :EMAILCC1- from &DATA;
Then applying a CC section to the code, to="&&&EMAILCC&I", if anyone has any guidance it would be great
* send mail from DATA;
%macro mailit(DATA);
%let NOBS=0;
* get emails from DATA;
proc sql noprint;
select distinct EMAIL into :EMAIL1- from &DATA;
select count(distinct EMAIL) into :EMAILN from &DATA;
quit;
* cycle through emails;
%do I=1 %to &EMAILN;
filename temp email to="&&&EMAIL&I"
type="text/html"
subject="OP Claims Daily Alert List";
ods html file=temp;
proc print data=&DATA noobs;
var ALERT;
var ALERT_DESC;
var ALERT_NAME;
var CI_CLAIM_ID;
var STDUSR_USER_FULLNAME;
var CH_CLAIM_TYPE;
var PRIORITY;
var GRP_GROUP_NAME;
where EMAIL="&&&EMAIL&I";
run;
ods html close;
%end;
%mend mailit;
%mailit(W714P7YT);
So you have a dataset with the email addresses in yes? Can you provide a sample as a datastep? Me I would go with:
data _null_; set email_addr end=last; by flag; if _n_=1 then call execute(cats('filename tmpmail to=("',mail,'")); else if first.flag and flag="bcc" then call execute(cats(') bcc=("',mail,'")); else call execute(cat(' "',mail,'")); if last then call execute('); data _null_; file tmpmail; put "Hello"; run;'); run;
This assumes a few things - as you have not supplied any information - in that you have a dataset called email_addr which looks like this:
FLAG MAIL
to abc@somewhere.com
to def@somewhere.com
bcc ghi@somewhere.com
The code goes through this dataset and generates the code need to email each of the people and the flag switches the addresses to bcc.
A simple data set would contain the below, need to be careful in terms of what I provide here;
Col_A | EMAILCC | |
123456789 | testemail@1234.com | testcc@1234.com |
987654321 | testemail@5678.com | testcc@5678.com |
Well, the simplest way is to create an intermediary dataset like mine looks by:
data inter; set have (keep=col_a mail rename=(email=mail) in=a) have (keep=col_a mail rename=(emailcc=mail) in=b); flag=ifc(a,"to","bcc"); run;
Then use inter with my given code.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.