Sample 46552: Embed images in a PROC REPORT table
The POSTIMAGE style attribute enables images to be embedded in a PROC REPORT column based on the value of a variable. POSTIMAGE requires a quoted string or a fileref, which cannot be created in a COMPUTE block. However, POSTIMAGE does enable you to specify a format. The same logic applies to the PREIMAGE style attribute.
The steps for embedding an image using POSTIMAGE and a format are:
- Name the image files using a value that is already contained in the data set.
- Build a format based on that variable and the location of the image files.
- Include the variable in the COLUMN statement and define it as a NOPRINT GROUP variable.
- Apply the format to the POSTIMAGE attribute in the DEFINE statement.
Please note that this sample uses the SAS/GRAPH® GPLOT procedure to create images to be inserted into the REPORT procedure output. You must have SAS/GRAPH licensed in order to run this sample.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
A GOPTIONS statement is used to control the size of the graph images. An additional format is used to blank out the values of the Year variable in the REPORT procedure output so that the column only contains the graph.
options nodate;
/* Create the graphs */
symbol1 interpol=join value=none;
axis1 label=none value=none major=none minor=none style=0;
%macro graphs;
%do yr=1980 %to 1985;
filename gsasfile "c:\&yr..png";
goptions device=png gsfname=gsasfile xmax=1 in ymax=1 in;
proc gplot data=sashelp.retail;
where year=&yr;
plot sales*month / vaxis=axis1 haxis=axis1;
run;
quit;
%end;
%mend graphs;
%graphs
/* Sort the data set and delete duplicates. */
/* We only need one record per year to create the format. */
proc sort data=sashelp.retail(where=(year < 1986)) out=retail nodupkey;
by year;
run;
/* Assign the necessary variables used by PROC FORMAT. */
data fmt;
set retail;
fmtname = "mypic";
start = year;
label = "c:\"||put(year,4.)||".png";
keep start fmtname label;
run;
/* Create the format containing the links to the images. */
proc format cntlin=fmt;
run;
/* Create a format to blank out values in the column that will contain the image. */
proc format;
value blank other=" ";
run;
ods listing close;
ods rtf file='sample.rtf';
ods pdf file='sample.pdf' notoc dpi=300;
ods html file='sample.html' style=sasweb;
title 'Embed Images in PROC REPORT Column';
proc report data=sashelp.retail nowd;
where year < 1986;
column year sales image;
define year / group;
define image / 'Sales trend for year' computed style(column)=[postimage=mypic. just=l cellwidth=1.5in ] format=blank.;
/* Set the computed variable equal to the variable */
/* value that matches the value in the $Mypic. format. */
compute image ;
image = year;
endcomp;
run;
ods _all_ close;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample demonstrates how to insert images as column values in PROC REPORT output.
Date Modified: | 2012-05-22 11:19:52 |
Date Created: | 2012-05-11 11:08:44 |
Operating System and Release Information
SAS System | Base SAS | z/OS | 9 TS M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9 TS M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9 TS M0 | |
Microsoft Windows 2000 Advanced Server | 9 TS M0 | |
Microsoft Windows 2000 Datacenter Server | 9 TS M0 | |
Microsoft Windows 2000 Server | 9 TS M0 | |
Microsoft Windows 2000 Professional | 9 TS M0 | |
Microsoft Windows NT Workstation | 9 TS M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9 TS M0 | |
Microsoft Windows Server 2003 Standard Edition | 9 TS M0 | |
Microsoft Windows XP Professional | 9 TS M0 | |
64-bit Enabled AIX | 9 TS M0 | |
64-bit Enabled HP-UX | 9 TS M0 | |
64-bit Enabled Solaris | 9 TS M0 | |
HP-UX IPF | 9 TS M0 | |
Linux | 9 TS M0 | |
OpenVMS Alpha | 9 TS M0 | |
Tru64 UNIX | 9 TS M0 | |