Previous Page | Next Page

SAS/GRAPH Colors and Images

Specifying Images in SAS/GRAPH Programs

SAS/GRAPH enables you to display images as part of your graph. You can place an image in the background area of a graph, in the backplane of graphs that support frames, or on the bars of two-dimensional bar charts. You can also apply images at specified graph-coordinate positions using the Annotate facility or the DATA Step Graphics Interface (DSGI).

The images you add to your graphs can be SAS files or external files, in a range of image formats.


Image File Types Supported by SAS/GRAPH

For displaying images in your graphs, SAS/GRAPH supports the image file types shown in the following table.

File Type Description
BMP (Microsoft Windows Device Independent Bitmap) supports color-mapped and true color images stored as uncompressed or run-length encoded. BMP was developed by Microsoft Corporation for storing images under Windows 3.0.
DIB (Microsoft Windows Device Independent Bitmap) see the description of BMP.
GIF (Graphics Interchange Format) supports only color-mapped images. GIF is owned by CompuServe, Inc.
JPEG (Joint Photographic Experts Group) supports compression of images with the use of JPEG File Interchange Format (JFIF) software. JFIF software is developed by the Independent Joint Photographic Experts Group.
PBM (Portable Bitmap Utilities) supports gray, color, RGB, and bitmap files. The Portable Bitmap Utilities is a set of free utility programs that were primarily developed by Jeff Poskanzer.
PCD (Photo CD) Kodak Photo CD format which supports multiple image resolutions.
PCX (PC Paintbrush) supports bitmap, color-mapped, and true color images. PCX and PC Paintbrush are owned by Zsoft Corporation.
PNG (Portable Network Graphic) supports truecolor, gray-scale, and 8-bit images.
TGA (Targa) supports true color images. Targa is owned by Truevision, Inc.
TIFF (Tagged Image File Format) internally supports a number of compression types and image types, including bitmap, color-mapped, gray-scale, and true color. TIFF was developed by Aldus Corporation and Microsoft Corporation.
XBM (X Window Bitmaps) supports bitmap images only. XBM is owned by MIT X Consortium.
XWD (X Window Dump) supports all X visual types (bitmap, color-mapped, and true color.) XWD is owned by MIT X Consortium.


Displaying an Image in a Graph Background

To place an image on the graph background, use the IBACK= option in a GOPTIONS statement. Specify either the path to the image file in quotation marks or a fileref that has been defined to point to the image file as follows:

goptions iback="external-image-file" | fileref;

For example, the following program creates a pie chart with a background image:

goptions reset=all 
          htitle=1.25 
         colors=(cx7c95ca cxde7d6f  cx66ada0
                 cxb689cd cxa9865b cxbabc5c)
         iback="external-image-file";
title "Projected Automobile Sales";
data sales;
    input Month Amount;
    informat month monyy.;
   datalines;
jan08 200
feb08 145
mar08 220
apr08 180
may08 155
jun08 250
;
proc sort;
   by month;
proc gchart;
   format month monname8.;
   pie month / discrete freq=amount value=inside
               noheading coutline=black;
run;
quit;

Because the default value for the IMAGESTYLE= graphics option is TILE, the image is copied as many times as needed to fill the background area.

[Pie Chart with Tiled Image in the Background]

You can specify IMAGESTYLE=FIT in the GOPTIONS statement to stretch the image so that a single image fits within the entire background area.

[Pie Chart with Stretched Image in the Background]


Displaying an Image in Graph Frame

Procedure action statements that support the IFRAME= support frames, which are the backplanes behind the graphs. The backplane is the area within the graph axes. To place an image on the backplane of a graph, specify the IFRAME= option in the procedure action statement that generates the graph. On the IFRAME= option, specify either the path to the image file in quotation marks or a fileref that has been defined to point to the image file:

 iframe=fileref | "external-image-file";

For example, the following program creates a vertical bar chart and adds an image to the graph frame:

goptions reset=all htitle=1.25 colors=(yellow cxde7d6f);
title "Projected Automobile Sales";
data sales;
    input Month Amount;
    informat month monyy.;
   datalines;
jan08 200
feb08 145
mar08 220
apr08 180
may08 155
jun08 250
;
proc sort;
   by month;
proc gchart;
   format month monname8.;
   vbar month / discrete freq=amount inside=freq
               coutline=black  iframe="external-image-file";
run;
quit;

Because the default value for the IMAGESTYLE= graphics option is TILE, the image is copied as many times as needed to fill the frame area.

[Bar chart with tiled image backgrount]

You can specify IMAGESTYLE=FIT in the GOPTIONS statement to stretch the image so that a single image fits within the entire frame area.

[Bar chart with stretched image]


Displaying Images on Data Elements

You can place images on the bars in two-dimensional bar charts generated by the GCHART HBAR or VBAR statements. You can also place images on the bars in three-dimensional bar charts if you are using the ACTIVEX device.

On the IMAGE= option of the PATTERN statement, specify either the path to the image file in quotation marks or a fileref that has been defined to point to the image file.

pattern image=fileref | "external-image-file";

By default, the image is tiled on the bar, which means that the image is copied as many times as needed to fill each bar. Specify IMAGESTYLE=FIT in the PATTERN statement to stretch the image as needed to fill each bar.

pattern image="external-image-file" imagestyle=fit;

To tile subsequent images, reset the PATTERN statement or by specify IMAGESTYLE=TILE.

Note:   Images are supported on bar charts generated by the HBAR and VBAR statements. If an image is specified on a PATTERN statement that is used with another type of chart, then the PATTERN statement is ignored and default pattern rotation is affected. If you submit a PIE statement when an image has been specified in the PATTERN= option, the default fill pattern is used for the pie slices. Each pie slice displays the same fill pattern.  [cautionend]

The following example places an image on the bars of a vertical bar chart:

goptions reset=all htitle=1.25 colors=(yellow cxde7d6f);
title "Projected Automobile Sales";
data sales;
    input Month Amount;
    informat month monyy.;
   datalines;
jan08 200
feb08 145
mar08 220
apr08 180
may08 155
jun08 250
;
proc sort;
   by month;
pattern1 image="external-image-file";
proc gchart;
   format month monname8.;
   vbar month / discrete freq=amount inside=freq
               coutline=black;
 run;
quit;

The image is tiled to fill each bar.

[Bar chart with tiled image]

If the PATTERN IMAGESTYLE=FIT option is used, the image is stretched to fill each bar.

 pattern=fileref | "external-image-file" imagestyle=fit;

[Bar chart with stretched image]


Displaying Images Using Annotate

The Annotate facility enables you to display an image at the coordinate location that you specify with the X and Y variables. To display an image, do the following:

One corner of the image is located by the current X and Y position. The opposite corner is located by the X and Y variables associated with the IMGPATH variable.

goptions reset=all border htitle=1.25
    hsize=5.5in vsize=4.2in;
data my_anno;
   length function $8;
   xsys="3";  ysys="3"; when="a";
function="move";  x=55;  y=55;  output;
function="image";  style="fit";  imgpath="external-image-file";
         x=x+15;  y=y+18;  output;
run;
title1 "GMAP with Annotated Image";
proc gmap data=maps.us map=maps.us anno=my_anno;
   id state;
   choro state/
   levels=1
   nolegend
   statistic=freq;
run;
quit;

The style="fit" variable on the IMAGE function stretches the image as needed to fill the area.

[GMAP with Annotate]

To tile the image to fill the area, set the STYLE variable equal to "tile" .

Displaying Images using DSGI

Using the DATA Step Graphics Interface (DSGI), you can display an image in a designated position. To display an image, specify the file specification for the image file in quotation marks on the GDRAW('IMAGE',...) function.

This code displays the image in the screen coordinates (20, 20) to (40, 40). The last parameter, FIT, indicates how to display the image.

rc=gdraw("image", "external-image-file", 20, 20, 40, 40, "fit");

Image File Types Supported by SAS/GRAPH shows the supported image file formats.

goptions reset=all 
   ftext="Albany AMT/bold" htitle=1.25
   hsize=5.5in vsize=4.2in;
title "DSGI with Image";
data image;
   rc=ginit();
   rc=graph("clear");
   rc=gdraw("image","external-image-file",
            5, 5, 90, 90,"tile");
   rc=graph("update");
   rc=gterm();
run;
quit;

If you specify the TILE keyword for the GDRAW('IMAGE',...) function, the image is copied as many times as needed to fill the specified area.

 rc=gdraw("image","external-image-file",
            5, 5, 90, 90,"tile");

[DSGI with tiled image]

If you specify the FIT keyword for the GDRAW('IMAGE',...) function, the image is stretched to fit within the entire area.

 rc=gdraw("image","external-image-file",
            5, 5, 90, 90,"fit");

[DSGI with stretched image]


Disabling and Enabling Image Output

The NOIMAGEPRINT graphics option disables image output without removing code from your SAS/GRAPH program. It is useful for printing output without images.

goptions noimageprint;

To enable image output, reset the GOPTIONS statement or specify the IMAGEPRINT graphics option.

goptions imageprint;

Previous Page | Next Page | Top of Page