BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Patrick
Opal | Level 21

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
  );
Patrick
Opal | Level 21

@JJP1 

Did the last version of the %_sendmail() macro now give you what you need?

JJP1
Pyrite | Level 9

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.

Patrick
Opal | Level 21

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. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to connect to databases in SAS Viya

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.

Discussion stats
  • 33 replies
  • 13065 views
  • 3 likes
  • 4 in conversation