Introduction

Why would you do this? My last post shows an embedded image in an RTF format, produced from SAS Proc Report. A natural follow on question would be, can it be in PNG, since such reports are more useful in PNG than RTF. That is it’s easier to insert a PNG into other documents etc. We wish this process of creating the PNG to be reproducible and avoid cut and paste, but Proc Report cannot be saved as PNG, so what can we do? One way to get round this if you are using Windows SAS is to call a VBS routine to print an RTF file to a PDF (there are probably other ways of doing this). Once in PDF then you can use R to convert it to PNG and other formats such as JPEG, SVG, and GIF etc. The image below uses this approach. Besides this being reproducible you can set the quality (dpi) of the final image! Note you could have used ODS PDF rather ODS RTF but there are advantages in RTF, such as the use of control words and easier on post-processing.

Method

** Proc_Report_RTF_to_PNG.SAS **;

ODS RTF file "temp.rtf";
Proc Repport;
  ....
Run;
ODS RTF Close;

** call VBS routine to convert RTF to PDF;
%RTF2PDF(infile = "temp.rtf", .., outfile = "temp.pdf");

** call SAS to R interface to run R codes that will convert PDF to PNG;
%callR(infile="temp.pdf", outfile="temp.png", dpi=300, trim=Y, ...);

   

Figure 1