Search code examples
sassas-macro

Sas macro send email


Hi I am trying to send mail from sas EG with macro. Please I have two questions:

  1. This code generates an error: "There is no matching %DO statement froe the %END. This statement will ignore"
  2. How can I change the HTML output style?

    %macro desicion;
       %if &dsempty=0 %then %do
          filename outbox email
          to=('smdy@mail.com')
    
          type='text/html'
          subject='Achtung!'
          from=('Robot@sender');
    
          ods html body=outbox rs=none;
    
          proc report data=work.final1 style=Analisis;
          run;
    
          ods html close;    
       %end;
    %mend;
    

Solution

  • 1) you forgot the ; after the %do

    %macro desicion;
    %if &dsempty=0 %then %do;
                   filename outbox email
                   to=('smdy@mail.com')
    
                   type='text/html'
                   subject='Achtung!'
                   from=('Robot@sender');
    
          ods html body=outbox rs=none;
    
          proc report data=work.final1 style=Analisis;
          run;
    
          ods html close;
    
    %end;
    %mend;
    

    2) That questions is a bit broad.

    You can apply a template style but that's doesn't always give the desired results.
    What I do is build a full html email with integrated css like this

        data _null_;
            file mymail;
            set DS end=eof;
    
            if _n_=1 then do;
                put '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
                put '<html xmlns="http://www.w3.org/1999/xhtml">';
                put '<head>';
                put '  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                put '  <title>TITLE</title>';
                put '  <style type="text/css">';
                put '    .row{width:100%;} ';
                put '    body {margin:0; padding:0;} ';
                ...
    

    EDIT: Here is link with more explanation on this method (cf. page 3)
    http://support.sas.com/resources/papers/proceedings10/060-2010.pdf