【问题标题】:Email SAS html output电子邮件 SAS html 输出
【发布时间】:2014-08-12 01:02:43
【问题描述】:

我正在使用 SAS Enterprise Guide 6.1。我正在尝试使用 Windows 调度程序批处理下面的程序以生成每周报告。它将有一些 proc prints 和 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;

【问题讨论】:

    标签: html email sas


    【解决方案1】:

    还有一个 DomPazz 没有提到的替代方案,为了完整起见,我将在此处包含它。我确实推荐这种方法,除非您发现自己处于以下情况:

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

    缺点

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

    概述

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

    我建议先对“html email cid”这个术语进行一些阅读/谷歌搜索,以熟悉这一点。您可能还想了解一下 base64 编码和 mime 类型。您无需成为专家,只需学习足以了解它们是什么以及它们大致如何工作即可。

    开发/测试

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

    构建 .html 文件和图表后,在网络浏览器中打开 .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

    【讨论】:

    • 感谢罗伯特的建议和阅读建议。绝对会为这个加星以供将来参考。
    【解决方案2】:

    图表未显示,因为它们对 html 查看器不可用。

    选项

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

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

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

    【讨论】:

    • 谢谢@DomPazz。我没有考虑过pdf输出。我用我的实际数据进行了尝试,但它太大而无法放在一页上,所以我必须弄乱选项并将其缩小。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 2015-08-14
    • 2013-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多