Wednesday, April 13, 2011

A Mass Mailing Macro

%macro emailit(mindsn=,mletter=letter,mfobs=1, mlobs=999999,msubject=,mattach=);
data letter; /* put letter in SAS file */
infile cards4 truncover; /* from cards below */
input @1 text $char100. ;/* input text field */
cards4; /* type letter text below */

Dear SAS User,
We are pleased to announce our latest class,
"Exploiting SAS ODS".
See you there.
Thank you,
Steven First
;;;; /* end of letter text */
run; /* end of step */

data _null_; /* go thru mail list and */
/* put all emails>mac vars*/
set &mindsn(firstobs=&mfobs obs=&mlobs) end=eof;
call
symput('memail'!!left(put(_n_,5.)),compress(email));
if eof then
call symput('mtotem',left(put(_n_,5.)));
run;

/****************************************************/
/* Loop through all the mac vars and send letter */
/****************************************************/
%do i=1 %to &mtotem;
filename emailf email "&&memail&i"
subject="&msubject";
data _null_;
file emailf attach="&mattach";
set &mletter;
put @1 text;
run;
%end;
%mend emailit;


/****************************************************/
/* Invoke the macro. */
/****************************************************/
%emailit(mindsn=mail.select, /* mail dataset */
mletter=letter, /* lett ds with text */
mfobs=1, /* 1st obs to send */
mlobs=1, /* last obs to send */
msubject=%bquote(Presenting our newest course
"Exploiting the SAS Output Delivery System"),
mattach=ods1.doc
;

No comments: