SAS html email output

I am using SAS Enterprise Guide 6.1. I am trying to execute the program below using the window scheduler to prepare a weekly report. It will have multiple proc and sgplots fingerprints. The user I'm posting is high level and doesn't have SAS (didn't know what to do with the program if he did). Ideally, I would like to just send him an attachment or even insert the graphs / results into an email for him to view. The program I seem to have generated the html file correctly, but when I open it in an email, the sgplots are not displayed. Any thoughts? Thank.

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;

      

+3


source to share


2 answers


Graphs are not displayed because they are not viewable in html.

Functions



  • You can write the images to an accessible location and make sure the paths in the generated html are correct.

  • Create a PDF or RTF file and write about it.

  • Use SVG (scalable vector graphics). This will require you to parse the output files and insert the XML for SVG into HTML.

+2


source


There is another alternative that DomPazz did not mention, and I will include it here for completeness. I do NOT recommend this approach unless you find in the following situation:

  • You are not allowed to use the attachment.
  • The only places where you can host images are either on the intranet server or HTTPS server.
  • Emails must be read from smartphones (which usually do not connect to a corporate VPN or cannot provide HTTPS credentials to download and display images).

against

  • This method is not directly supported by SAS.
  • This requires third party tools (such as BLAT - http://www.blat.net/ ).
  • HTML emails are known to be quite thin when rendered, so you have to keep them valid.
  • This is not for the faint of heart.

Overview

The basic premise is that you create your diagrams as images on disk, create your HTML file on disk, and then use a third party tool to send email. The third party tool will embed the charts in the email, and the generated HTML will link to the inline images using a so called CID (content-ID).

I suggest reading / googling a bit on the terms "html email cid" to get to know this first. You can also read a little information about base64 encoding and mime type. You don't need to become an expert, just study enough to know what they are and how they work.

Development / Testing

You can still use ODS to create your file .html

, but be sure to use ODS HTML3

one that forces SAS to use an older version of HTML. It also makes it repeat the style for each element. You need this because email clients like Outlook actually use the MS Word engine to render HTML emails.

Once you've created your .html file and charts, open the .html file in a web browser and make sure it displays correctly.

Once your output is displayed as you wish in your web browser, you still have a few more changes that you must make before sending them as email. When developing in your browser, you would notice that you have embedded an image like this:

<img src="my_image.png" />

      



Well, we cannot do this for email, we need to use the CID link like this:

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

      

When we use BLAT to send email, we will provide images to embed. Image names will be automatically used for legend CID:

.

You can send a message using BLAT like this:

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

      

What about it. Maybe if I get more time I can get the complete code with a working example.

Some helpful indications:

http://24ways.org/2009/rock-solid-html-emails (READ THIS !!)

http://www.emailology.org

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

HTML address alignment by email

+3


source







All Articles