Problem Note 57098: Combining the PREIMAGE= attribute and FORMAT= in PROC REPORT might produce an empty cell for character variables
You can embed an image in a table cell with PROC REPORT using the PREIMAGE= or POSTIMAGE= attribute. Often the path and image name are placed in a format so that different images can be placed within each cell. Sometimes a second format is also used to blank out the value of the variable so that it is not displayed in the cell with the image. When the variable is a character variable, the second format might be incorrectly applied before the preimage format is applied. The result is a blank cell.
To circumvent the problem, do one of the following:
- Remove the format that is used to blank out the value. The image appears in the cell. However, the text value of the variable appears as well.
- Create a numeric variable with a unique value that corresponds to each of the character values.
Click the Full Code tab to see code that demonstrates the problem behavior and the workaround of creating a numeric variable. Click the Results tab to see the output.
Sample 46552 , "Embed images in a PROC REPORT table", also contains an example of embedding an image using a format on a numeric variable.
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.4 TS1M1 | |
z/OS 64-bit | 9.4 TS1M1 | |
Microsoft® Windows® for x64 | 9.4 TS1M1 | |
Microsoft Windows 8 Enterprise 32-bit | 9.4 TS1M1 | |
Microsoft Windows 8 Enterprise x64 | 9.4 TS1M1 | |
Microsoft Windows 8 Pro 32-bit | 9.4 TS1M1 | |
Microsoft Windows 8 Pro x64 | 9.4 TS1M1 | |
Microsoft Windows 8.1 Enterprise 32-bit | 9.4 TS1M1 | |
Microsoft Windows 8.1 Enterprise x64 | 9.4 TS1M1 | |
Microsoft Windows 8.1 Pro | 9.4 TS1M1 | |
Microsoft Windows 8.1 Pro 32-bit | 9.4 TS1M1 | |
Microsoft Windows Server 2008 | 9.4 TS1M1 | |
Microsoft Windows Server 2008 R2 | 9.4 TS1M1 | |
Microsoft Windows Server 2008 for x64 | 9.4 TS1M1 | |
Microsoft Windows Server 2012 Datacenter | 9.4 TS1M1 | |
Microsoft Windows Server 2012 R2 Datacenter | 9.4 TS1M1 | |
Microsoft Windows Server 2012 R2 Std | 9.4 TS1M1 | |
Microsoft Windows Server 2012 Std | 9.4 TS1M1 | |
Windows 7 Enterprise 32 bit | 9.4 TS1M1 | |
Windows 7 Enterprise x64 | 9.4 TS1M1 | |
Windows 7 Home Premium 32 bit | 9.4 TS1M1 | |
Windows 7 Home Premium x64 | 9.4 TS1M1 | |
Windows 7 Professional 32 bit | 9.4 TS1M1 | |
Windows 7 Professional x64 | 9.4 TS1M1 | |
Windows 7 Ultimate 32 bit | 9.4 TS1M1 | |
Windows 7 Ultimate x64 | 9.4 TS1M1 | |
64-bit Enabled AIX | 9.4 TS1M1 | |
64-bit Enabled Solaris | 9.4 TS1M1 | |
HP-UX IPF | 9.4 TS1M1 | |
Linux for x64 | 9.4 TS1M1 | |
Solaris for x64 | 9.4 TS1M1 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
The first code sample below demonstrates using a computed character variable to insert an image into a cell by applying a format in the PREIMAGE= attribute. The resulting output contains a blank cell. The second code example illustrates the workaround of using a numeric variable as the computed variable.
/* Use a computed character variable and a format to suppress the value */
proc sort data=sashelp.class out=class nodupkey;
by sex;
run;
data fmt;
set class;
fmtname = "$mypic";
start = sex;
label = "c:\"||sex||".png";
keep start fmtname label;
run;
proc format cntlin=fmt;
run;
proc format;
value $blank other=" ";
run;
title 'Embedded Images Do Not Appear in Computed Character Column';
proc report data=sashelp.class nowd;
column sex height image;
define sex / group;
define image / 'Height Over Age' computed style(column)=[postimage=$mypic. just=l cellwidth=1.5in ] format=$blank.;
compute image /char ;
image = sex;
endcomp;
run;
/* Workaround: Use a numeric variable */
proc sort data=sashelp.class out=class;
by sex;
run;
proc sort data=class out=class1 nodupkey;
by sex;
run;
data class2;
set class1;
by sex;
num + 1;
run;
/* Both formats, MYPIC and BLANK, are changed to numeric */
data fmt;
set class2;
fmtname = "mypic";
start = num;
label = "c:\"||sex||".png";
keep start fmtname label;
run;
proc format cntlin=fmt;
run;
proc format;
value blank other=" ";
run;
data class;
merge class class2(keep=sex num);
by sex;
run;
title 'Use a Numeric Variable to Embed Images in a Computed Column';
proc report data=class nowd;
column sex num height image;
define sex / group;
define num / group noprint;
define image / 'Height Over Age' computed style(column)=[postimage=mypic. just=l cellwidth=1.5in ] format=blank.;
compute image;
image = num;
endcomp;
run;
Type: | Problem Note |
Priority: | medium |
Date Modified: | 2015-12-04 16:24:53 |
Date Created: | 2015-11-17 15:05:15 |