Below a fully working new cut of the %_sendmail() macro with all the parameters you've asked for. You know where it has to go.
When calling the macro only parameter TO is required.
/* send email
- attaches CSV if macro variable &attachFLG=1
*/
%macro _sendmail(
to=,
from=,
sender=,
cc=,
subject=,
importance=,
attachCSV=&attachFLG
);
/* add single quotes around selected parameters */
data _null_;
length param_name $20 param_val $1000;
do param_name='to','cc','importance';
param_val=compbl(symget(param_name));
if not missing(param_val) then
do;
param_val=cat("'",tranwrd(strip(param_val)," ","' '"),"'");
call symputx(param_name,param_val);
put param_name '=' param_val;
end;
end;
stop;
run;
filename outbox email (&to)
%if %nrbquote(&from) ne %nrbquote() %then from="&from";
%if %nrbquote(&sender) ne %nrbquote() %then sender="%nrbquote(&sender)";
%if %nrbquote(&cc) ne %nrbquote() %then cc=(&cc);
%if %nrbquote(&subject) ne %nrbquote() %then subject="%unquote(%nrbquote(&subject))";
%if %nrbquote(&importance) ne %nrbquote() %then
%do;
%let importance=%upcase(&importance);
%if &importance='LOW'
or &importance='NORMAL'
or &importance='HIGH'
%then
importance=&importance;
%end;
;
/* no attachements */
%if &attachCSV=0 %then
%do;
data _null_;
file outbox
/* subject="Data from process - no attachments"*/
;
put 'Folks,';
put 'There is no data today';
put 'This email sent without attachments';
run;
%end;
/* with attachements */
%else %if &attachCSV=1 %then
%do;
%local attachments;
%let attachments=;
%do i=1 %to &_INPUT_count;
%let attachments=&attachments %unquote(%nrstr(%')&&_INPUT&i%nrstr(%'));
%end;
data _null_;
file outbox
/* subject="Data from process - with attachments"*/
attach=(&attachments);
;
put 'Folks,';
put 'Attached the latest cut of data';
run;
%end;
filename outbox clear;
%mend;
%_sendmail(
to=dummy@dummy.com ,
from=dummy@dummy.com,
sender=dummy@dummy.com,
cc=dummy@dummy.com,
importance=HIGH,
subject=your daily mail
);
Did the last version of the %_sendmail() macro now give you what you need?
Sorry @Patrick for coming back late, i thank you for kind response and guiding ,encouraging me to learn SAS more deeply.
It is working as i expected. iam sorry i know that i troubled you much.Thank you.
Great that this now worked for you.
This was certainly a discussion on the intense side and your thank you is appreciated. No reason to apologize though - no one forced me to stay on it.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.