I am not sure if there is any practical use for sending emails through SAS. But this SAS micro was picked up from RTP SAS User Group Email List and it works very well. The credit goes to Mr Ping Ling.
%macro sendemail(to=,cc=,subj=,msg1=,msg2=,msg3=,msg4=,msg5=,msg6=,msg7=,msg8=,attach=);
FILENAME mail EMAIL (&to.)
EMAILID='Microsoft Outlook'
SUBJECT="&subj."
%if &cc. ne %then %do;
cc="&cc."
%end;
%if &attach. ne %then %do;
attach="&attach."
%end;
;
%let today=%sysfunc(date(),date9.);
DATA _NULL_;
FILE mail;
PUT "&today.";
PUT;
PUT "&msg1.";
%do i=2 %to 8;
%if &&msg&i. ne %then %do;
%if %sysfunc(compress("&&msg&i."))="/n" %then %do; put; %end;
%else %do; PUT "&&msg&i. "; %end;
%end;
%end;
put;
run;
%mend;
/*Example for using the macro
%sendemail(to=%str('abc123@hotmail.com','xxx@gmail.com'),
subj=%str(Sending email with SAS),
msg1=%str(This is a test.),
msg2=%str(/n),
msg6=%str(xxxx)
);
*/
FILENAME mail EMAIL (&to.)
EMAILID='Microsoft Outlook'
SUBJECT="&subj."
%if &cc. ne %then %do;
cc="&cc."
%end;
%if &attach. ne %then %do;
attach="&attach."
%end;
;
%let today=%sysfunc(date(),date9.);
DATA _NULL_;
FILE mail;
PUT "&today.";
PUT;
PUT "&msg1.";
%do i=2 %to 8;
%if &&msg&i. ne %then %do;
%if %sysfunc(compress("&&msg&i."))="/n" %then %do; put; %end;
%else %do; PUT "&&msg&i. "; %end;
%end;
%end;
put;
run;
%mend;
/*Example for using the macro
%sendemail(to=%str('abc123@hotmail.com','xxx@gmail.com'),
subj=%str(Sending email with SAS),
msg1=%str(This is a test.),
msg2=%str(/n),
msg6=%str(xxxx)
);
*/