电子邮件SAS html输出

时间:2014-08-12 01:02:44

标签: html email sas

我正在使用SAS Enterprise Guide 6.1。我正在尝试使用Windows调度程序批处理下面的程序以生成每周报告。它将有一些proc打印和sgplots。我发送给它的用户是高级的,没有SAS(如果他这么做,就不知道如何处理该程序)。理想情况下,我只想通过电子邮件向他发送附件,或者甚至将图表/结果嵌入到电子邮件中,这样他就可以查看它们。我的程序似乎正在正确创建html文件,但是当我在电子邮件中打开它时,sgplots没有显示。有什么想法吗?感谢。

filename temp email to="cthulhu@gmail.com"
                    subject="Testing the report"
                    type="text/html"
                    attach='/sasdata/cthulhu/email.html';

ods html path='/sasdata/cthulhu' file='email.html' gpath='/sasdata/cthulhu' style=htmlblue;

data have;
    input name $ class $ time score;
cards;
chewbacca wookie  1 97
chewbacca wookie 2 100
chewbacca wookie 3 95
saruman wizard 1 79
saruman wizard 2 85
saruman wizard 3 40
gandalf wizard 1 22
gandalf wizard 2 50
gandalf wizard 3 87
bieber canadian 1 50
bieber canadian 2 45
bieber canadian 3 10
;
run;

proc sql noprint;
    select count(distinct class) into :numclass
    from have;
    %let numclass=&numclass;
    select distinct class into :class1 - :class&numclass
    from have;
    select count(distinct name) into :numname
    from have;  
    %let numname=&numname;
    select distinct name into :name1 - :name&numname
    from have;
quit;

%macro printit;
%do i = 1 %to &numclass;
title "Report for &&class&i";
proc print data=have;
    where class="&&class&i";
run;
%end;
%mend;
%printit;

%macro plotit;
%do i = 1 %to &numname;
title "Plot for &&name&i";
proc sgplot data=have(where=(name="&&name&i"));
    series x=time y=score
    / legendlabel='score' markers lineattrs=(thickness=2);
    xaxis label="time";
    yaxis label='score';
run;
%end;
%mend;
%plotit;

ods html close;

data _null_;
   file temp;
   put 'This is a test';
run;

2 个答案:

答案 0 :(得分:3)

还有一个替代方案,DomPazz没有提及,为了完整起见,我会在此处加入。除非您发现自己处于以下情况,否则 NOT 推荐此方法:

  1. 您不得使用附件。
  2. 您可以放置​​图像的唯一位置是在Intranet或HTTPS服务器上。
  3. 电子邮件必须可从智能手机读取(通常不会连接到公司VPN或能够提供HTTPS凭据以下载和显示图像)。
  4. <强>缺点

    • SAS不直接支持此方法。
    • 它需要第三方工具(例如BLAT - http://www.blat.net/)。
    • HTML电子邮件在渲染时已经非常挑剔,因此您必须保持简单。
    • 这不适合胆小的人。

    <强>概述

    基本前提是您将图表创建为磁盘上的图像,在磁盘上创建HTML文件,然后使用第三方工具发送电子邮件。第三方工具会将图表嵌入到电子邮件中,您创建的HTML将使用所谓的CID(内容ID)引用嵌入的图像。

    我建议您在“html email cid”条款上进行一些阅读/谷歌搜索,以便首先熟悉这一点。您可能还想对base64编码和mime类型进行一些阅读。你不需要成为一名专家,只需要足够了解它们是什么以及它们的工作原理。

    <强>开发/测试

    您仍然可以使用ODS创建.html文件,但请务必使用ODS HTML3强制SAS使用较旧版本的HTML。它还强制它重复每个元素的样式。您需要这个,因为Outlook等电子邮件客户端实际上使用MS Word引擎来呈现HTML电子邮件。

    构建.html文件和图表后,在Web浏览器中打开.html文件并确保其正确显示。

    在网络浏览器中根据需要显示输出后,您仍需要进行一些更改,然后才能将其作为电子邮件发送。在浏览器中进行开发时,您会注意到嵌入了这样的图像:

    <img src="my_image.png" />
    

    我们不能为电子邮件做到这一点,我们需要像这样使用CID链接:

    <img src="cid:my_image.png" />
    

    当我们使用BLAT发送电子邮件时,我们将指定要嵌入的图像。图像名称将自动用于CID:命名约定。

    您可以使用BLAT发送电子邮件,如下所示:

    blat test.html -f "myemailaddress@myemailaddress.com" -subject "test" -html -alttextf test.html -embed test.png -server mail.mysmtpserver.com -to myrecipient@recipentemail.com 
    

    就是这样。也许如果我有更多的时间,我将提供一个完整的代码和一个工作示例。

    一些有用的阅读材料:

    http://24ways.org/2009/rock-solid-html-emails(阅读此!!)

    http://www.emailology.org

    http://www.campaignmonitor.com/css/

    HTML email align text

答案 1 :(得分:2)

图表未显示,因为html查看器无法使用它们。

选项

  1. 您可以将图像写入可用的位置,并确保生成的html中的路径正确无误。

  2. 生成PDF或RTF文件并通过电子邮件发送。

  3. 使用SVG(可缩放矢量图形)。这将要求您解析输出文件并将SVG的XML嵌入到HTML中。