DATA Step, Macro, Functions and more

Email from SAS

Reply
Contributor
Posts: 64

Email from SAS

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

Super User
Super User
Posts: 9,829

Re: Email from SAS

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.  

Contributor
Posts: 64

Re: Email from SAS

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                    
Super User
Super User
Posts: 9,829

Re: Email from SAS

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.  

Ask a Question
Discussion stats
  • 3 replies
  • 110 views
  • 1 like
  • 2 in conversation