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

Hello. I need to send by mail more than one embedded chart. The following sentence works correctly when it is one but I can not send more than one chart. Can you also indicate how to send an e-mail and a proc report and a sgplot proc?

 

Thanks!

 

*/
%let workdir=%trim(%sysfunc(pathname(work)));
ods graphics on / width=10 in height=3.5in;
ods _ALL_ close;
ods listing gpath="&workdir";
ods graphics / reset=index outputfmt=PNG imagename='email'; 
title1 'Evolucion de produccion';

 
  proc sgplot data=GRAFICO_SC noborder ;
    VLINE FECHA_CONTABLE / response=STOCK group=SISTEMA_NOMBRE y2axis lineattrs=(color=red) dataskin=pressed name='a';
    vline FECHA_CONTABLE / response=avg_DESPACHO  group=sistema_nombre  lineattrs=(color=gray pattern=solid) dataskin=pressed  name='b';
  vline FECHA_CONTABLE / response=PRODUCCION group=sistema_nombre  lineattrs=(color=blue pattern=solid) nostatlabel name='C';
    xaxis discreteorder=data display=(noline nolabel noticks);
 axis1  value=(font="Verdana" angle=90);
    y2axis display=(noline noticks) grid label='Stock' valueshint  offsetmin=0;
    yaxis display=(noline noticks) offsetmin=0;
    keylegend  'a' 'b' 'C' / title='' linelength=24;

 run;
filename sendmail email to=("user@domain.com") from=("user@domain.com")
     attach=("&workdir./email.png" inlined='sgplot')
     type='text/html' subject="Evolucion ";
      data _null_;
 file sendmail; 
 put '<html>';
 put '<body>';
 put '<img src=cid:sgplot>';
 put '</body>';
 put '</html>';
run;
      filename sendmail clear;

 

1 ACCEPTED SOLUTION

Accepted Solutions
MartinMincey
SAS Employee

Hello,

 

At this point, your code looks pretty good.  But I do have a few more suggestions for you. 

 

At the very top of your code, before you create your graphics output, reset any active/old titles and footnotes by adding the following two statements to the code:

 

title1;

footnote1;

 

Then, move the following two statements:

 

footnote1 '<img src=cid:graf1>';
footnote2 '<img src=cid:graf2>';

 

Down a bit so that they now appear right after the following statement:

 

ods html3 file=sendmail style=sasweb;

 

Let me know if this does not resolve the issue. 

 

Regards, Martin

 

 

View solution in original post

9 REPLIES 9
MartinMincey
SAS Employee

To send multiple graphs via email, you can specify multiple graphs for the ATTACH option on the FILENAME statement and then add additional PUT statements to the DATA step code (one PUT statement per graph).  Here is sample code which demonstrates this:

 

filename sendmail email
       to      = ("first.last@company.com" )
       from    = ("first.last@company.com")
       attach  = ("&workdir.\email1.png"  inlined='email1'   "&workdir\email2.png"   inlined='email2')
       type    = 'text/html'
       subject = "Email test of GRAPH output";

data _null_;
   file sendmail; 
   put '<html>';
   put '<body>';
   put '<img src=cid:email1>';
   put '<img src=cid:email2>';
   put '</body>';
   put '</html>';
run;

filename sendmail clear; 

 

Below is sample SAS code which emails a graph followed by PROC REPORT output.  The graph is added to the email via the following TITLE statement in the code (right before the PROC REPORT step):

 

title1 '<img src=cid:sgplot>';

 

Here is the sample code:

 

filename sendmail email

to = ("first.last@company.com" )

from = ("first.last@company.com")

attach = ("&workdir.\sgplot.png" inlined='sgplot')

type = 'text/html'

subject = "Email test of GRAPH output";

ods _all_ close;

ods html3 file=sendmail style=sasweb;

title1 '<img src=cid:sgplot>';

proc report data=sashelp.class;

run;

ods html3 close;

ods listing;

filename sendmail clear;

 

 

LorenaPalacios
Calcite | Level 5

thank you!! Your example to créate

More than one charts worked perfectly but when I try to add the Report below just like the example, the mail show an "x" where the graph should go and then the report. Any suggestions?

I show you the code  

thanks again (sorry for my english)

 

%let workdir=%trim(%sysfunc(pathname(work)));

ods graphics on / width=10 in height=3.5in;

ods _ALL_ close;

ods listing gpath="&workdir";

ods graphics / reset=index outputfmt=PNG imagename='graf1';

proc sgplot data=GRAFICO_C noborder ;

           title bold 'Prueba1';

   VLINE FECHA_CONTABLE / response=STOCK y2axis lineattrs=(color=red) dataskin=pressed name='a';

   vline FECHA_CONTABLE / response=avg_DESPACHO   lineattrs=(color=gray pattern=solid) dataskin=pressed name='b';

     vline FECHA_CONTABLE / response=PRODUCCION   lineattrs=(color=blue pattern=solid) nostatlabel name='C';

   xaxis discreteorder=data display=(noline nolabel noticks) valueattrs=(family="Arial" size=4) ;

   y2axis display=(noline noticks) grid label='Stock Neto m3' valueshint offsetmin=0;

   yaxis display=(noline noticks) label='Producción/Despachos m3' /*values=(0.34 to 0.46 by 0.02)*/ offsetmin=0;

   keylegend 'a' 'b' 'C' / title='' linelength=24;

run;

 

%let workdir=%trim(%sysfunc(pathname(work)));

ods graphics on / width=10 in height=3.5in;

ods _ALL_ close;

ods listing gpath="&workdir";

ods graphics / reset=index outputfmt=PNG imagename='graf2';

proc sgplot data=GRAFICO_Cole noborder ;

           title bold 'Prueba2';

   VLINE FECHA_CONTABLE / response=STOCK y2axis lineattrs=(color=red) dataskin=pressed name='a';

   vline FECHA_CONTABLE / response=avg_DESPACHO   lineattrs=(color=gray pattern=solid) dataskin=pressed name='b';

     vline FECHA_CONTABLE / response=PRODUCCION   lineattrs=(color=blue pattern=solid) nostatlabel name='C';

   xaxis discreteorder=data display=(noline nolabel noticks) valueattrs=(family="Arial" size=4) ;

   y2axis display=(noline noticks) grid label='Stock Neto m3' valueshint offsetmin=0;

   yaxis display=(noline noticks) label='Producción/Despachos m3' /*values=(0.34 to 0.46 by 0.02)*/ offsetmin=0;

   keylegend 'a' 'b' 'C' / title='' linelength=24;

run;

 

filename sendmail email to=("first.last@company.com") from=("first.last@company.com")

        attach = ("&workdir.\graf1.png" inlined='graf1'   "&workdir.\graf2.png"   inlined='graf2')

     type='text/html' subject="Emailing graphics output";

     options emailsys=smtp;

    options emailhost="xxx";

ods _all_ close;

 

ods html3 file=sendmail style=sasweb;

title1 '<img src=cid:sgplot>';

proc report data=sashelp.class;

run;

ods html3 close;

ods listing;

filename sendmail clear;

 

 

MartinMincey
SAS Employee
Hello, Since on the following statement you named your two graphs GRAF1 and GRAF2 using the INLINED option: filename sendmail email to=("first.last@company.com") from=("first.last@company.com") attach = ("&workdir.\graf1.png" inlined='graf1' "&workdir.\graf2.png" inlined='graf2') type='text/html' subject="Emailing graphics output"; To then reference the first graph later on in the code, modify the following statement: title1 ''; So that it references GRAF1, for example: title1 ''; Additionally, if you want to place GRAF1 before the report and GRAF2 after the report, you can use: title1 ''; footnote1 ''; Regards, Martin
MartinMincey
SAS Employee

Hello,

 

Since my last reply was not formatted correctly, let me try one more time...

 

Since on the following statement you named your two graphs GRAF1 and GRAF2 using the INLINED option:

 

filename sendmail email to=("first.last@company.com") from=("first.last@company.com")

attach = ("&workdir.\graf1.png" inlined='graf1' "&workdir.\graf2.png" inlined='graf2')

type='text/html' subject="Emailing graphics output";

 

To then reference the first graph later on in the code, modify the following statement:

 

title1 '<img src=cid:sgplot>';

 

So that it now looks like this:

 

title1 '<img src=cid:graf1>';

 

Additionally, if you want to place GRAF1 before the report and GRAF2 after the report, you can use:

 

title1 '<img src=cid:graf1>';

footnote1 '<img src=cid:graf2>';

 

Regards, Martin

 

 

 

 

 

LorenaPalacios
Calcite | Level 5

Thank you very much for your response.

It has helped me a lot, however  in each graphic below the legend I add the text " '<img src=cid:graf1>" just like I show you in the example.

I need all the graphics after the report

I  copy the code to verify that it is correct.

Thanks again you has been really very kind

 

 

 

 

 


filename sendmail email to=("firstname@company.com") from=("firstname@company")
      attach = ("&workdir.\graf1.png" inlined='graf1'   "&workdir.\graf2.png"   inlined='graf2')
      type='text/html' subject="Emailing graphics output";
      options emailsys=smtp;
   options emailhost="xxx";
ods _all_ close;

footnote1 '<img src=cid:graf1>';
footnote2 '<img src=cid:graf2>';

ods html3 file=sendmail style=sasweb;
proc report data=sashelp.class;
run;

ods html3 close;
ods listing;
filename sendmail clear;

MartinMincey
SAS Employee

Hello,

 

At this point, your code looks pretty good.  But I do have a few more suggestions for you. 

 

At the very top of your code, before you create your graphics output, reset any active/old titles and footnotes by adding the following two statements to the code:

 

title1;

footnote1;

 

Then, move the following two statements:

 

footnote1 '<img src=cid:graf1>';
footnote2 '<img src=cid:graf2>';

 

Down a bit so that they now appear right after the following statement:

 

ods html3 file=sendmail style=sasweb;

 

Let me know if this does not resolve the issue. 

 

Regards, Martin

 

 

LorenaPalacios
Calcite | Level 5
 
I have 3 proc report and 2 proc sgplot. I have to send the first graph after the second report and the second graph after the third report. Might you help me? I can not locate them correctly Thank you very much
MartinMincey
SAS Employee

Hello,

 

If your two graphs are named GRAF1 and GRAF2 on the ATTACH option on the FILENAME statement, you should be able to accomplish this by structuring your code similar to the following...

 

title1; footnote1;  

proc report data=sashelp.cars;

where make="Honda";

run;

proc report data=sashelp.cars;

where make="Audi";

run;

title1 '<img src=cid:sgplot>';

footnote1 '<img src=cid:sgplot1>';

proc report data=sashelp.cars;

where make="BMW";

run;

 

Where the TITLE1 and FOOTNOTE1 statements in this case appear only before the third PROC REPORT step. 

 

Regards, Martin

MartinMincey
SAS Employee

Hello,

 

I did have a typo in my last reply.  If the graphs are named GRAF1 and GRAF2, the code should actually look similar to the following...

 

title1; footnote1;  

proc report data=sashelp.cars;

where make="Honda";

run;

proc report data=sashelp.cars;

where make="Audi";

run;

title1 '<img src=cid:graf1>';

footnote1 '<img src=cid:graf2>';

proc report data=sashelp.cars;

where make="BMW";

run;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 2951 views
  • 1 like
  • 2 in conversation