BookmarkSubscribeRSS Feed
Aidan
Quartz | Level 8

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

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

Aidan
Quartz | Level 8

A simple data set would contain the below, need to be careful in terms of what I provide here;

 

Col_AEMAILEMAILCC
123456789testemail@1234.comtestcc@1234.com                    
987654321testemail@5678.comtestcc@5678.com                    
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

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
  • 3 replies
  • 827 views
  • 1 like
  • 2 in conversation