• Print  |
  • Feedback  |

Knowledge Base

TS-674

An Introduction to Exporting SAS/Graph Output to Microsoft Office SAS Release 8.2 and higher

This document includes in-depth information about the different formats and methods you can use to export SAS/GRAPH output to Microsoft Office 97, 2000, and XP. This document has been updated to include new features that are now available in SAS 9. Throughout the document, logos are used to indicate where new features are available in SAS 9.0 or SAS 9.1.

  1. Introduction
  2. Factors to Consider When Choosing a Format
    1. A. Can the Image be Edited? - Vector and Raster Formats
    2. B. Image Resolution
    3. C. Fonts
      1. Hardware vs. Software
      2. The FreeType Library
      3. Listing Available Fonts
        1. Listing system fonts on Windows
        2. Listing system fonts on Unix
        3. Listing Fonts Available Through FreeType
      4. Referencing Font Names and Attributes
    4. Image Size
    5. Images per File
      1. Graphics formats vs. document formats
      2. Multi-image graphics files
      3. Multiple graph files from one procedure to separate files
  3. Generating the Output
    1. EMF and WMF
      1. Advantages and Limitations
      2. Differences in the Device Drivers
      3. Fonts
      4. Methods
        1. Copy and paste (Windows systems only)
        2. File > Export (Windows systems only)
        3. Device driver (all operating systems)
        4. ODS RTF (all operating systems)
    2. CGM
      1. Advantages and Limitations
      2. Differences in the Device Drivers
      3. Fonts
      4. Method
      5. Microsoft Office Restrictions
      1. Installing the default import filter
      2. Modifying the Windows Registry on Windows NT and Windows 2000 systems
      3. Metric-scaled and abstract-scaled Images
      4. The advanced import filter
      5. Importing multiple pictures from the same CGM file
    3. JPEG, PNG, TIFF
      1. Advantages and Limitations
      2. Fonts
        1. System Fonts
        2. Using Fonts through FreeType
      3. Methods
        1. File > Export
        2. Device Driver
        3. ODS RTF
      4. Changing the Resolution of the Output
    4. GIF and BMP
      1. Advantages and Limitations
      2. Fonts
        1. System fonts
        2. Using Fonts through FreeType
      3. Methods
        1. File > Export
        2. Device Driver
    5. EPS
      1. Advantages and Limitations
      2. Fonts
      3. Methods
        1. Device Driver
        2. Universal Printer
      4. Adding a TIFF or WMF Preview
    6. HTML
      1. Advantages and Limitations
      2. Fonts
      3. Method
        1. Page Setup
        2. Basic Syntax
        3. Combining tabular and graphics output
    7. RTF
      1. Advantages and Limitations
      2. Fonts
      3. Method
        1. Page Setup
        2. Basic Syntax
        3. Combining tabular and graphics output
  4. Examples
    1. Creating a full-size EMF graph
    2. Creating a CGM file containing multiple graphs
    3. Creating High Resolution JPEG, PNG, or TIFF output
    4. Changing the attributes of the graphs within RTF documents
    5. Changing the page layout for ODS PRINTER or ODS RTF output using the OPTIONS statement
    6. Changing the margins for ODS PRINTER or ODS RTF output using the TEMPLATE procedure
    7. Combining graphs in a single graphics file using GREPLAY
    8. Combing text and graphics output with ODS HTML or ODS RTF
    9. Sample statements for non-Windows systems
      1. Unix and HFS Mainframe Systems
        1. Create a single file
        2. Create many files in a directory
        3. Create a document
      2. MVS Systems
        1. Create a single file
        2. Create many files in a directory
        3. Create a document

I. Introduction

SAS/GRAPH can export to many of the different graphics file formats that Microsoft Office can import. These include:

◈ EMF Enhanced Windows Metafile
◈ WMF Windows Metafile
◈ CGM Computer Graphics Metafile
◈ JPEG Joint Photographic Experts Group file interchange format
◈ PNG Portable Network Graphic
◈ TIFF Tagged Image File Format
◈ GIF Graphics Interchange Format
◈ BMP Windows Bitmap

In addition, the Output Delivery System can be used to create documents that contain multiple graphs in one of the above formats. These include:

◈ HTML HyperText Markup Language documents with GIF, JPEG, PNG, or ACTIVEX graphs
◈ RTF Rich Text Format documents with EMF, JPEG, PNG, or ACTIVEX graphs
◈ EPS Encapsulated PostScript documents containing PostScript graphics

Document formats make is possible to combine graphs and text output, such as tables and reports. When creating graphs for these documents, restrictions of both the graphics format and the document format must be considered.

II. Factors to Consider When Choosing a Format

A. Can the Image Be Edited? - Vector and Raster Formats

The information to produce a graphic image is typically stored in one of two ways: as instructions to draw the elements in the graph, or as a static representation of the final image.

In a vector format, the objects are described by instructions, such as specifying an origin, radius, and rotation to create a circle. This stored information is used to render the object directly to the display or printer. Resizing the image or its elements does not degrade the quality.

Vector Formats: EMF, WMF, CGM, EPS

In some programs, such as Microsoft Word and Microsoft PowerPoint, you can edit the individual elements in the vector image, such as the titles and other text strings, or the graph's bars or axes. This is true for EMF, WMF, and CGM images. The EPS format can contain vector graphs, but Office programs cannot edit EPS files.

Raster or bitmap graphics are a static representation of the image stored as a finite number of colored dots called pixels. Objects in the graph are mapped to a grid, and the color of each square, or pixel, in this grid is stored, and not the information to recreate the object.

Raster/Bitmap Formats: GIF, TIFF, JPEG, PNG, BMP

If you resize a raster formatted image, the quality will decrease; therefore you should try to create these images at the size you need. Programs like Adobe Photoshop or Microsoft Paint will allow you to edit raster images, although the editing is done pixel by pixel.

Typically a vector format provides a better-quality image than a raster format, although with some raster formats you can improve the quality of the image by increasing the resolution.

B. Image Resolution

Raster or bitmap graphics are stored as a finite number of colored dots called pixels. More pixels per inch means a higher resolution image, but the maximum resolution is ultimately limited by the capabilities of the output device, such as the monitor or printer, which renders the final image.

The JPEG, PNG, and TIFF formats can store images at different resolutions. The default resolution for the JPEG, PNG, TIFFB, and TIFFP device drivers is 95dpi. You can easily increase the output resolution of graphs created using the JPEG, PNG, or TIFF series of device drivers to match that of the output device by specifying the XMAX, YMAX, XPIXELS, and YPIXELS parameters on the GOPTIONS statement. An example is given in section IV.C.

The resolution of the GIF and BMP formats cannot be changed. This is a restriction of the formats, not the device drivers.

C. Fonts

1. Hardware vs. Software

For creating text, every device driver can use the SAS software fonts such as SWISS, ZAPF, CENTX, and SIMULATE. The availability of this common font set allows you to use the same fonts in your code and output when exporting graphics on different operating systems and with different device drivers. However, using a hardware font, one native to the graphics format, can often produce clearer results. The list of available hardware fonts varies by operating system, format, and device driver. Commonly recognized font sets include system fonts and a standard subset of PostScript fonts.

With EMF, WMF, and CGM graphics, text created in a hardware font will be editable after the graph is imported into Microsoft Office. Using hardware fonts will also reduce the size of the output file in these formats and in the EPS format. With the raster formats, none of the text in the graph will be editable, but text in a hardware font may appear clearer in the output.

For the document formats RTF and HTML, fonts for text outside the graphs, such as tables and sometimes titles and footnotes, are specified using a style sheet. A list of similar fonts may be specified, and the receiving application will choose the first that is available or that most closely matches the requested font. Text in the graphs that are stored in or with these documents are limited to the fonts supported by the device drivers used to create them.

See Section III for the hardware fonts available with each format.

2. The FreeType Library

A new font rendering engine, FreeType, has been incorporated into SAS 9.1. In this release, the FreeType rendering engine allows SAS to use TrueType fonts on any operating system SAS supports. The SASEMF device driver and most image device drivers such as GIF, JPEG, and PNG support this new feature. FreeType allows for a wider variety of hardware fonts in these formats, and provides support for hardware fonts on systems that may not otherwise have it.

Information is given in the OnlineDoc in SAS 9.1 for:

  • adding fonts to the operating system
  • using the FONTREG procedure to update the font list in the SAS Registry
  • and modifying the SAS/GRAPH device drivers to recognize these fonts

See also sections III.C.2.b and III.D.2.b for information on modifying the device drivers to recognize fonts available through the FreeType library. The SASEMF device driver includes FreeType support by default.

3. Listing Available Fonts

The available software fonts are listed in the OnlineDoc in the SAS/Graph Software Reference under SAS/Graph Fonts, Using SAS Software Fonts. A sample of each font is shown in this list next to the font name.

The hardware fonts available to a particular device driver are named in the Chartype list of that driver. To display this list, you can submit the following code:

proc gdevice c=sashelp.devices nofs;
list DeviceDriverName;
run;quit;

Replace DeviceDriverName with the name of the device driver you want listed; for example, EMF. To list multiple device drivers, use multiple LIST statements. The device driver information is displayed in the Output window in an interactive SAS session and to the .LST file in a batch session.

The Chartype list may list several fonts by name, or it may only list one font, such as "DMS Font" or "<ttf> SAS Monospace". For device drivers that list several fonts by name, you should use these exact names to reference the fonts in your code. For device drivers that only list "DMS Font", you can use system fonts, where available. If the font "<ttf> SAS Monospace" is listed, the device driver has been enabled for FreeType support.

a. Listing system fonts on Windows

When SAS is run on a Windows system, those device drivers that list the "DMS Font" will recognize the Windows system fonts, typically TrueType fonts. These are the same fonts you would use in Microsoft Office. To see a list of available TrueType fonts on a Windows system, you can use the font browser in the Microsoft Office application or in SAS. In SAS select the File menu, choose Print Setup, and then click the Fonts button. Any font with the icon next to its name is a TrueType font.

b. Listing system fonts on Unix

The system fonts available from the Xwindows server on a Unix system can be listed by invoking either the XLSFONTS or XFONTSEL utilities at a Unix prompt. XFONTSEL is an interactive tool. XLSFONTS can be used to create a list of all the font names. For example, the following will redirect the XLSFONTS output to a file called FONTS.TXT:

xlsfonts > fonts.txt

You can use either the complete, long names or the abbreviated names given at the end of the list. If the Xwindows server is not available to the SAS session, and you are running a release previous to SAS 9.1, then only software fonts can be used with device drivers that list "DMS Font". See SAS Note 4663 for more information.

In SAS 9.1, sessions that do not have access to an Xserver can use the new FreeType support instead. FreeType can read and render the font information, so the Xserver is not necessary. Device drivers that normally list "DMS Font" must be modified before they will support fonts through the FreeType library. See sections III.C.2.b and III.D.2.b

c. Listing Fonts Available Through FreeType

After loading the fonts into the SAS Registry using the FONTREG procedure, you can list the fonts available through FreeType using the SAS Registry or the REGISTRY procedure. Launch the SAS Registry editor, and expand the following key: core\printing\freetype\fonts. Or submit the following to have the contents of this key printed to the log:

proc registry list
startat="core\printing\freetype\fonts";
run;quit;

You should use these font names in your SAS code. These names may differ from the names displayed when the font list is generated by another application.

The font type is listed as part of the font name, such as "<ttf> SAS Monospace" for SAS Monospace, a TrueType font. This prefix is optional when you reference the font in your code. It is available to distinguish different types of fonts with the same name.

Device drivers that normally list "DMS Font" must be modified before they will support fonts through the FreeType library. See sections III.C.2.b and III.D.2.b. The SASEMF device driver is already enabled for FreeType support.

4. Referencing Font Names and Attributes

Software fonts are generally referenced without quotes, such as FONT=SWISS. Attributes are appended to the font name, such as SWISSB for SWISS bold.

Hardware font names should always be referenced in quotes, such as FONT="Courier New". If the syntax already requires a set of quotes, use two sets. For example, the annotation variable STYLE normally requires quotes: STYLE=&148;SWISS&148;. As discussed in SAS Note 1473, to specify a hardware font for this variable, two sets of quotes are required: STYLE=&148;&146;Helvetica&146;&148;. It does not matter which kind of quote is outside the other, as long as they are balanced. The length of the STYLE variable must be great enough to store the font name and one set of quotes.

For system fonts, attributes should follow a forward slash "/" after the font name, such as FONT="Courier New/bold". Common attributes include: BOLD, ITALIC, and a combination of both. You can also abbreviate attributes, such as BO for BOLD and IT for ITALIC.

To help distinguish them from other hardware fonts, fonts available through the FreeType library may include their file type as a prefix to the font name. For example, the SAS Monospace TrueType font could be referenced as "<ttf> SAS Monospace". Font attributes should follow a forward slash "/" after the font name: "<ttf> SAS Monospace/bold". Only attributes listed for that font in the SAS Registry will be valid.

For device drivers that do not support system fonts or the FreeType library, use only the names available in the font list, such as FONT="Courier". Attributes for these fonts are a part of the font name, such as FONT="CourierBold", as shown in the Chartype list.

D. Image Size

Each of the device drivers discussed in this document has a default output size. These sizes range from 2x2 inches to 12x15 inches depending on the device driver and operating system where SAS is running. To list the default and maximum allowable output sizes for a device driver, use the GDEVICE procedure:

proc gdevice c=sashelp.devices nofs;
list DeviceDriverName;
run;quit;

Replace DeviceDriverName with the name of the device driver you want to see, such as EMF. The information is sent to the Output window in an interactive SAS session and the .LST file in a batch session. The maximum output size is listed in the XMAX and YMAX fields. The default output size can be calculated as (HSIZE-HORIGIN) by (VSIZE-VORIGIN). If these four parameters are zero, then the default output size is the same as the maximum output size.

You can change the output size using the HSIZE and VSIZE parameters on the GOPTIONS statement. The values for HSIZE and VSIZE cannot exceed the maximum size allowed by the device driver, XMAX and YMAX. In SAS 8.2 and beyond, if you want to make a larger image, you can temporarily override the XMAX and YMAX values in the device driver entry using the XMAX and YMAX parameters on the GOPTIONS statement.

When creating RTF documents in SAS 8.2, it may be necessary to additionally specify the same device driver as the DEVICE and TARGET to get the proper output size. By default, this ODS destination sets the TARGET to SASPRTC. To be sure the values you have specified are honored set the size, DEVICE, and TARGET on the GOPTIONS statement. An example is given in section IV.D

Sizing parameters can be specified with units of inches or centimeters, such as XMAX=8in or VSIZE=10cm.

E. Images per File

1. Graphics formats vs. document formats

Most graphics format files are designed to contain strictly graphical information and possibly some text such as titles, footnotes, or legends. These files are often inserted into existing documents to enhance the presentation. They normally only contain one image per file.

Document formats, such as HTML and RTF, are capable of storing multi-page documents that contain both graphics and text. These formats store graphs in one of three ways:

• in the format of the document.
• in a graphics formats within the document.
• separately in an external file which is referenced by the document.

The EPS format can store graphics directly in the document format. The RTF format stores the images in the document using a standard graphics file format such as EMF, JPEG, or PNG. The HTML format may contain ActiveX or Java images, or it may link to external JPEG, GIF, or PNG graphics files.

Microsoft Office can only import single-page Encapsulated PostScript files as discussed in section III.E. It can import multi-page RTF and HTML files. The RTF format was designed to exchange documents between word processors; it is recommended that this format be used to export to Microsoft Word only. Microsoft PowerPoint and Microsoft Excel will not load graphics along with RTF documents. In Office 97, only Word will load images along with HTML documents.

2. Multi-image graphics files

The CGM and GIF formats can each store multiple images, or 'pictures', per file. In Office 97, the Microsoft Office import filter will only import the first picture from a multi-picture GIF file. You can create an HTML document to easily load multiple GIF images into Word instead. Office 2000 and Office XP can import all the images from a multi-picture GIF file when the file is created as an animated GIF. An animated GIF will replay each image in sequence, like a movie. In PowerPoint, the image will play during the slide show view of the presentation. In Word, the image will play only if the document is saved as an HTML file.

The Office 97 CGM import filter can import multiple images from the same CGM file. First, an enhanced filter must be installed in addition to the default CGM import filter (see section III.B.5.d). It is still not possible to import all the pictures in one step; each image from the CGM file must be imported individually, just as if the images were stored in separate files.

You can combine multiple graphs into a single image before exporting by using the GREPLAY procedure. When this templated image is imported, the graphs will all appear on the same page because they are part of the same image. An example of using the GREPLAY procedure is given in section IV.G.

3. Multiple graph files from one procedure to separate files

In SAS 6.12, it was not possible to store each graph created using BY-group or RUN-group processing in a separate file without using macro processing. In SAS 7 and beyond, you can do this easily by assigning the FILENAME statement to point to a directory location, not a specific file. Then as each graph is created, it will be automatically written to a separate file in the specified directory. The files are named using the corresponding graphics catalog entry names and given an extension that corresponds to the export format used. For more information, see the OnlineDoc, &147;The SAS/Graph Software Reference,&148; &147;SAS/Graph Output&148;, "Exporting SAS/GRAPH Output with Program Statements".

In SAS 9.1, you will receive an error if you try to create PNG, JPEG, or EMF graphs using an aggregate storage location. In these releases, you must also specify the NOFILEONLY option on the GOPTIONS statement when using aggregate storage. See SAS Note 13155 for more information.

If you wish to explicitly name each file using a name other than the catalog entry name, macro processing would still be required. For example, the catalog entry name would not reflect the value of each BY-group. For an example of naming the files using the BY-group values, see Technical Support Document 698: Storing Graphs Generated with BY-Group Processing in Separate Files.

III. Generating the Output

The specific requirements for creating output in each format are described in separate sections below.

A. EMF and WMF

1. Advantages and Limitations

The Enhanced Windows Metafile and Windows Metafile formats were designed to store graphics on Windows systems. Most Windows-based applications recognize these formats, and graphs stored in EMF or WMF can usually be edited after they are imported. These graphs are imported at full size into Office, and can be resized without degrading the image. For these reasons, the EMF format is highly recommended when SAS is also running on a Windows system.

The EMF and WMF formats do have certain limitations you should consider. First, the EMF format does not support transparency. To have the background of the graph match the document or slide background, you could use the CBACK or IBACK options on the GOPTIONS statement to assign the same color or image for the graph background. Alternately, you could edit the EMF file after it is imported to remove the default background. See also the problem documented in SAS Note 010976.

Second, the EMF format supports one picture per file. You can use the ODS RTF destination to export multiple EMF graphs in the same file to Microsoft Word.

2. Differences in the Device Drivers

The EMF and WMF device drivers were first introduced in SAS 7. Although this format is Windows-based, SAS/GRAPH supplies these device drivers on all operating systems.

There are a total of four SAS/Graph device drivers that produce EMF and WMF output: EMF, WMF, SASEMF, and SASWMF. Originally there were two, EMF and WMF, but the EMF and WMF device drivers on non-Windows systems behave differently than the EMF and WMF device drivers on Windows systems. This is because the EMF and WMF formats are Windows-based, so on Windows systems they can borrow system information to create the output. SAS had to develop a different, native method for creating these files on non-Windows systems. Copies of these native device drivers were added to Windows systems in SAS 8.2 and named SASEMF and SASWMF. The SASEMF and SASWMF device drivers were also made available on non-Windows systems. Only the EMF and WMF device drivers on Windows system rely on system information to create the output; all other device drivers rely only on SAS to create the output.

Table 1: Comparison of EMF and SASEMF device drivers

Windows Systems All Other Operating Systems
1. EMF-System Dependent 2. EMF-SAS Native
3. SASEMF-SAS Native 4. SASEMF-SAS Native

Be aware that the size of the output from the EMF and WMF device drivers can vary on different operating systems.

By default, graphs created with the ODS RTF destination use the SASEMF device driver on all systems.

3. Fonts

Because these formats are Windows-based, they recognize the Windows system fonts, the TrueType fonts. When SAS is running on a Windows operating system, the EMF and WMF device drivers can use any TrueType font available on that system. When running on a non-Windows system the EMF device driver includes a subset of these fonts in its Chartype list. The available fonts include the Courier, Courier New, and Letter Gothic fonts. The SASEMF device driver uses this same subset of fonts on all systems.

In SAS 9.1, the SASEMF device driver also supports fonts through the FreeTypelibrary. It is not necessary to modify the device driver to support these fonts.

Table 2: Comparison of Fonts Available with the EMF and SASEMF device drivers

Windows Systems All Other Operating Systems
EMF-System fonts EMF-Native fonts
SASEMF-Native fonts and FreeType SASEMF-Native fonts and FreeType

The WMF device driver on non-Windows systems and the SASWMF device driver on all systems only recognize the fonts included in their Chartype lists.

The font is not embedded in the EMF or WMF file; therefore the font must also be available on the recipient's system in order for the text to be rendered correctly. If the font is not available, Microsoft Office will try to substitute a similar font.

4. Methods

You can generate EMF graphs in several different ways. Because the format is Windows-based, some of the methods are only available on Windows systems, as indicated:

a. Copy and paste (Windows systems only)

  1. When viewing the graph in the Graph window, resize the window if desired, and then choose Edit => Copy from the menu. Do NOT lasso or select individual pieces of the graph before copying.
  2. In a Microsoft Office document, choose from the menu Edit => Paste special => Picture(Enhanced Metafile). The graph will be pasted as an EMF file.

b. File => Export (Windows systems only)

  1. When viewing the graph in the Graph window, resize the window if desired and then choose File => Export as Image from the menu.
  2. From the export dialog, choose EMF as the file type, select a location, enter a filename, and click Save.
  3. From an Office document, choose Insert => Picture => From file and select the file you just created.

c. Device driver (all operating systems)

  1. Use a FILENAME statement and a GOPTIONS statement in your SAScode to write the graph directly to an EMF file:
    filename output 'myfile.emf';
    goptions device=emf gsfname=output gsfmode=replace;
    /* graph code goes here */
    run;quit;
  2. From an Office document, choose Insert => Picture => From file. and select the file you just created.

In SAS 9.1, you will receive an error if you try to create EMF graphs in an aggregate storage location. In these releases, you must also specify the NOFILEONLY option on the GOPTIONS statement when using aggregate storage. The SASEMF device driver does not require this option. See SAS Note 13115 for more information.

d. ODS RTF (all operating systems)

The SASEMF device driver can be used with the ODS RTF destination on all systems. See section III.G for more information.

B. CGM

The CGM format is a cross-platform graphics format capable of storing multiple images per file.

1. Advantages and Limitations

Graphs stored as CGM can be edited after they are imported. The images may not be imported at full size in Office as discussed under &147;Differences in Device Drivers&148; below. The image can be resized without degradation.

The format does not support transparency. You can use the CBACK option on the GOPTIONS statement to assign the same background color to the CGM file as the document or slide. The device drivers do not support the IBACK option. To have an image in the document or slide appear as the background of the graph, edit the graph after it is imported to remove the background created by SAS.

Microsoft Office requires additional setup before it can import CGM graphs. You must first install the Microsoft Office CGM import filter before you can import these files. See section III.B.5.a for more information on setting up Office.

The format does support multiple images per file. See sections III.B.5.d and III.B.5.e.

2. Differences in Device Drivers

Because the Microsoft Office CGM import filter is virtually unchanged between Office 97, Office 2000, and Office XP, the recommended CGM device drivers for exporting to Microsoft Office are the same for all three releases of Office. These are the CGMOF97L and CGMOF97P device drivers. The first creates landscape output while the second creates portrait output.

In SAS 9.0, two new device drivers were added: CGMOFML and CGMOFMP. These two device drivers allow CGM images to be imported at full-size into Office. They can be used with Office 97 and higher. The CGMOFML device driver creates landscape-oriented images while the CGMOFMP device driver creates portrait-oriented output. See III.B.5.c for more information.

3. Fonts

By default, the Microsoft Office CGM import filter recognizes the Base 14 PostScript fonts as hardware fonts. These fonts include:

Table 3: CGM Hardware Fonts

Helvetica HelveticaBold HelveticaItalic

HelveticaBoldItalic

TimesRoman

TimesRomanBold TimesRomanItalic

TimesRomanBoldItalic

Courier

CourierBold

CourierItalic CourierBoldItalic

Symbol

   
ZapfDingbats

   

Each of the recommended device drivers uses these fonts on all systems.

Once imported to Office, the image can be edited, and text in these fonts will be displayed using TrueType fonts with the following substitutions:

Table 4: CGM Hardware Fonts and Their TrueType Counterparts

CGM PostScript Font TrueType Font
Helvetica Arial
TimesRoman Times New Roman
Courier Courier New
Symbol Symbol
ZapfDingbats Wingdings

The CGM device drivers do not use fonts from the FreeType library.

4. Method

CGM files can only be exported from code using one of the CGM device drivers. Use a FILENAME statement and a GOPTIONS statement in your SAS code to write the graph directly to a CGM file:

filename output 'myfile.cgm';
goptions device=cgmofml gsfname=output gsfmode=replace;
/* graph code goes here*/
run;quit;

From an Office document, choose Insert > Picture > From file and select the file you just created. You must installthe CGM import filter in Office before you can import the image. See section III.B.5

You can export a multi-image CGM file by creating multiple graphs from the same procedure, such as when using BY-group processing or the GREPLAY procedure. Each of the graphs will be appended to the designated CGMfile. Complete examples of creating such files are given in section IV.B and IV.G. Microsoft Office requires additional setup before it can import multiple images from the same file. See section III.B.5.d for more information.

5. Microsoft Office Restrictions

a. Installing the default import filter

Microsoft Office does not include the CGM import filter as a part of the default installation. Before any CGM files can be imported, the following steps must be taken:

Office 97:

  1. Select Start > Settings > Control Panel from the system menu.
  2. Double-click on Add/Remove Programs.
  3. Click on Microsoft Office and then the Add/Remove button.
  4. When the setup window appears, click on the Add/Remove button.
  5. Click on Converters and Filters and click on Change Option.
  6. Click on Graphics Filters and click on Change Option.
  7. Check on the Computer Graphics Metafile Import box and click OK.

Office 2000 and Office XP:

  1. Select Start > Settings > Control Panel from the system menu.
  2. Double-click on Add/Remove Programs.
  3. Click on Microsoft Office and then the Add/Remove button.
  4. When the setup window appears, click Add or Remove Features.
  5. Click on the plus sign next to Converters and Filters.
  6. Click on plus sign next to Graphics Filters.
  7. Check on the Computer Graphics Metafile Import box and select Run From My Computer.
  8. Select the Update Now button

b. Modifying the Windows Registry on Windows NT and Windows 2000 systems

If Microsoft Office is installed on a Windows NT or Windows 2000 system, a change may be required in the Windows Registry before the import filter can be used. See the following Microsoft support articles:

For Office 97: 172921

For Office 2000: 220200

c. Metric-scaled and abstract-scaled Images

The CGM format supports two methods for describing the location of objects in the graph: metric scaling and abstract scaling. Essentially, metric-scaled images use absolute values, such as 2 in or 4.5 cm, to set the sizeof the image and position objects. Abstract-scaled images use relative sizing, where the size and position of objects are relative to the size of the image area. This method is similar to using percentages of the output area to describe coordinates, such as (50%, 50%) for the center of the image.

Because the actual size of abstract-scaled images is not known, the Microsoft Office import filter constrains these CGM files to 4x4inches by default. Metric-scaled images are imported at full-size.

In previous releases, SAS/Graph has created abstract-scaled CGM files by default, and the CGMOF97L and CGMOF97P device drivers still create abstract-scaled images. Changing the output size from SAS does not have an effect on the size of the imported image, only the aspect ratio. Graphs created with these device drivers must be resized after they are imported if a larger image size is desired.

In SAS 9.0, two new device drivers were added, CGMOFML and CGMOFMP. These two device drivers create metric-scaled CGM images. These images will import at actual size in Office.

 

d. The advanced import filter

If the CGM file contains multiple images, the CGM import filter will only import the first image by default. This import filter is not available in all releases of Office.

1) Office 97

To be able to import other images from the file into Office 97 applications, a secondary import screen must be activated as follows:

  1. Make sure that the convert8.wiz file is on your system. It should be located in the c:\Microsoft Office\Office\Macros subdirectory. If it is there, skip to step nine. If it is not present, continue with the next step.
  2. Select class=MenuItem>Start > Settings > Control Panel from the system menus.
  3. Double-click on class=MenuItem>Add/Remove Programs.
  4. Click on class=MenuItem>Microsoft Office 97 and then the class=MenuItem>Add/Remove button.
  5. When the Setup window appears, click on the class=MenuItem>Add/Remove button.
  6. Select class=MenuItem>Microsoft Word, and click on the class=MenuItem>Change Option button.
  7. Select class=MenuItem>Wizards and Templates, and click on the class=MenuItem>Change Option button.
  8. Select class=MenuItem>Macro Templates and click class=MenuItem>OK. The convert8.wiz file will be installed.
  9. You must use Microsoft Word to run the Conversion Wizard. Within Word, choose class=MenuItem>File > Open.
  10. Change to the class=MenuItem>Microsoft Office\Office\Macros folder.
  11. In the class=MenuItem>Files of Type box, click class=MenuItem>All Files. Double-click class=MenuItem>convert8.wiz.
  12. If the warning dialog box appears, click class=MenuItem>Open With Macros.
  13. In the Conversion Wizard dialog box, click class=MenuItem>Edit converter or filter options.
  14. In the Conversion list, click class=MenuItem>Computer Graphics Metafile.
  15. In the Options box, select class=MenuItem>ShowOptionsDialog=No.
  16. Click class=MenuItem>Yes to change this option, click class=MenuItem>OK, and then click class=MenuItem>Close.

2) Office 2000

You must apply Service Pack 3 for Office 2000 before you can activate the advanced import filter in this release. See articles 326665 and 326585 in the Microsoft Knowledge Base for more information.

3) Office XP

The advanced import filter cannot be activated in Office XP. In this version, you will only be able to import the first image from a CGM file.

e. Importing multiple pictures from the same CGM file

After the advanced import filter screen has been activated in Office 97 or Office 2000, it is possible to select which picture to import as follows:

  1. From an Office document, choose Insert > Picture > From file and select the CGM file.
  2. After you click the Insert button, a second dialog should appear. Click the Picture button from this dialog.
  3. In the Picture field, indicate which picture you want to import, such as "1" for the first image in the file, "2" for the second, and so on.
  4. Click OK to insert the picture.

You must repeat these steps to import each image from the file. There is no method to import all images from a CGM file at once.

C. JPEG, PNG, TIFF

1. Advantages and Limitations

JPEG, PNG, and TIFF are all raster formats.

The JPEG format is widely used for web graphics but was originally developed to store complex images such as photographs. The format uses a lossy compression method to reduce the file size that may also introduce noise (inaccuracies) in the image. The noise can be more obvious images with large blocks of continuous color, such as graphs.

The PNG format is a fairly new format for displaying graphics on the web. It was designed to combine the best properties of the GIF and JPEG formats. PNG uses a lossless compression method, so the image does not degrade as the information to store the file is compressed. The PNG format supports transparency, but the SAS/Graph PNG device driver does not (SN 12442).

The TIFF format is not a web graphics format, but it is a good format for exchanging images between other programs.

Each of these formats is capable of storing high resolution, true-color images. When generating graphics to these formats from SAS, it is possible to adjust the resolution of the output using parameters on the GOPTIONS statement. An example is given below in section IV.C.

Both JPEG and PNG graphics can be stored in an RTF file. TIFF images cannot. See section III.G.3 for information on using these formats with this destination.

2. Fonts

a. System Fonts

These formats generally recognize system fonts as hardware fonts. Text in a system font or a software font is rasterized in these formats. However, at low resolutions, using system fonts can produce sharper-looking output because of the difference in the way the text is rendered. Because the text is stored as pixels, not text strings, font substitutions will not occur on the recipient's system.

b. Using Fonts through FreeType

In SAS 9.1, the JPEG, PNG, TIFFP, and TIFFB device drivers can be modified to recognize the fonts available through the FreeType library. First the fonts have to be installed on the system and added to the SAS Registry, using the instructions in the SAS 9.1 OnlineDoc. Then the device drivers Chartype list must be modified to include the "SAS Monospace" font.

To make the change, first assign a LIBNAME to designate a location to store the modified device driver. This library should be named GDEVICE0. Use the GDEVICE procedure to change the first font in the CHARTYPE list from "DMS Font" to SAS Monospace:

libname gdevice0 'location';
proc gdevice c=gdevice0.devices nofs;
copy png from=sashelp.devices newname=pngft;
modify pngft charrec=(1,1,1,'SAS Monospace','y');
run;quit;

Specify DEVICE=PNGFT in the code to be able to use fonts from the FreeType library in the output. After creating the device driver, you can access it whenever the same GDEVICE0 libname is in effect. This means you do not need to rerun the GDEVICE procedure in subsequent SAS sessions, only assign the same LIBNAME statement.

3. Methods

a. File > Export

After generating the graph to the Graph window, resize the window if desired and then select the File menu and then Export or Export as Image. Choose JPEG, PNG, or TIFF as the file type, designate a location and filename, and save the graph.

From an Office document, choose Insert > Picture > from File from the menu, select the graph, and click Insert.

b. Device Driver

JPEG and PNG graphics can be created using the JPEG and PNG device drivers, respectively. TIFF output can be generated using the TIFFB device driver for monochrome output or the TIFFP device driver for color output.

Table 5: JPEG, PNG, and TIFF Device Drivers

Format Device Driver
PNG PNG
JPEG JPEG
TIFF (color) TIFFP
TIFF (monochrome) TIFFB

Use a FILENAME statement and a GOPTIONS statement to designate a storage location and device driver. The file extension on the FILENAME statement should match the format defined by the DEVICE on the GOPTIONS statement:

filename output 'myfile.jpg';
goptions device=jpeg gsfname=output gsfmode=replace;
/* graph procedure goes here */
run;quit;

From an Office document, choose Insert > Picture > From file and select the file you just created.

Prior to SAS 9.1, JPEG and PNG images can only be created on an HFS file system. See SAS Note 1761 for more information.

In SAS 9.1, you will receive an error if you try to create PNG or JPEG graphs in an aggregate storage location. In these releases, you must also specify the NOFILEONLY option on the GOPTIONS statement when using aggregate storage. See SAS Note 13115 for more information.

c. ODS RTF

JPEG and PNG graphics can also be used for RTF output. See section III.G for more information.

4. Changing the Resolution of the Output

In previous releases of SAS it was only possible to adjust the output resolution for the TIFF device drivers by modifying the device driver itself. In SAS 8.2 and beyond, you can create high resolution JPEG, PNG, or TIFF images by setting the XMAX, YMAX, XPIXELS, and YPIXELS options on the GOPTIONS statement. The ratio of pixels-per-inch in each dimension determines the resolution of the file. For example:

goptions dev=png xpixels=1200 ypixels=900 xmax=4 in ymax=3 in;

These GOPTIONS set the resolution of the PNG image to 300pixels per inch. See an example of changing the resolution of the output in section IV.C.

For exporting to Microsoft Office, resolutions of 300 or 600dpi are typically recommended. If the document will be printed to a printer that supports higher resolutions, such as 1200dpi, you could create a 1200ppi graph instead. There is no limit on the resolution you can specify. However, the higher the resolution, the larger the file size, and the more resources it takes to create the file. Setting a high resolution when creating a large number of graphs may cause problems in the output. See SAS Note 8846.

Changing image resolution can also affect the number rows and columns in the output. You may want to adjust the text height and line weights when creating high-resolution images. For example, at high resolutions the width of lines in the output may appear faint. In SAS 9.0 and beyond, you can use the LFACTOR option on the GOPTIONS statement to increase the thickness of all lines in the output. It is recommended that the line thickness increase by the same factor as the resolution. For example, if you triple the resolution from 95ppi to 300ppi, you may also want to triple the line thickness: LFACTOR=3. In SAS 8.2, the LFACTOR option is ignored by these device drivers, so you would need to set the line widths on the individual statements in the code, such as on AXIS and SYMBOL statements (SAS Note 8121).

You can also use the PNGSZ macro to create a new device driver at the desired resolution. This macro also lets you adjust the default font size and line thickness (for SAS 9 and higher). The information about this macro is also given in SAS Note 13133.

/*
The PNGSZ macro creates a new device driver at the specified size and resolution. The LFACTOR and default text height can also be set. The parameters are as follows:

ParameterDescriptionDefault Value
DPIresolution600
NEWDEVname of new device driverPNG
PTSIZEdefault height of text, in points12
Wdefault width of output8.5
Hdefault height of output11
UNITSunit of measurement for H and WIN (inches)
LIBREFlibrary; the new device driver is stored in LIBREF.devices. The libname must be defined before the macro is run.GDEVICE0
*/

%macro PNGSZ(dpi=600, newdev=PNG, ptsize=12, w=8.5, h=11, units=IN, libref=GDEVICE0);
%let XPIXELS = %sysevalf(&dpi * &w);
%let YPIXELS = %sysevalf(&dpi * &h);
%let ROWS = %sysevalf(&h / (&PTSIZE/72), floor);
%let LFACTOR = %sysevalf(&dpi / 100, floor); proc gdevice c=&libref..devices nofs noprompt;
copy PNG from=sashelp.devices newname=&newdev;
mod &newdev
xmax = &w &units ymax = &h &units
xpixels = &XPIXELS ypixels = &YPIXELS
lrows = 0 lcols = 0
prows = &ROWS pcols = 70
lfactor=&lfactor
devopts = '3502304009280008'x
%if &sysver GE 9.1 %then
charrec = (0, 1, 1, 'SAS Monospace', 'Y');
;
quit;
%mend PNGSZ;

This example uses the macro to create a 300dpi device driver named PNG300 in the catalog GDEVICE0.DEVICES which is in the same location as the SASUSER library:

libname gdevice0 "%sysfunc(pathname(sasuser))";
%pngsz(dpi=300,newdev=PNG300);

In subsequent SAS sessions, the GDEVICE0 library must be assigned before the device will be available. However, you will not need to recreate the device using the macro. If you are running SAS 9.1 or higher, it is recommended that the FONTREG procedure be run before using this device driver to provide additional fonts. If you will be using the device driver with the ODS RTF destination, the name of the new device driver must be the same as the original, as documented in SAS Note 13130.

D. GIF and BMP

1. Advantages and Limitations

The GIF and BMP formats are both raster formats that were designed to store simple images. The GIF format uses lossless compression to reduce the file size without affecting the image quality when storing the image. Both formats have a resolution of approximately 95dpi, and this resolution cannot be changed.

The GIF format supports transparency. Use the TRANSPARENCY option on the GOPTIONS statement to remove the background, and any object that is the same color as the background, from the image. The background color is set using the CBACK option on the GOPTIONS statement.

The GIF format can also store multiple images per file if the output is formatted as an animated GIF file. Programs that display the animated GIF file will replay the images in sequence, like a movie. Section III.D.3.b has more information on creating these files, including how Microsoft Office programs will display these files.

2. Fonts

a. System fonts

The GIF, GIF733, GIFANIM, and BMP device drivers recognize system fonts as hardware fonts. Using system fonts with these formats can produce sharper looking output than software fonts because of the difference in the fonts themselves. The GIF570, GIF373, GIF260, and GIF160 device drivers will only recognize software fonts.

b. Using Fonts through FreeType

In SAS 9.1, the GIF, GIF733, and BMP device drivers also recognize fonts available through the FreeType library. First the fonts have to be installed on the system and added to the SAS Registry, using the instructions in the SAS 9.1 OnlineDoc. Then the device drivers Chartype list must be modified to include the "SAS Monospace" font.

To make the change, first assign a LIBNAME to designate a location to store the modified device driver. This library should be named GDEVICE0. Use the GDEVICE procedure to change the first font in the CHARTYPE list from "DMS Font" to SAS Monospace:

libname gdevice0 'location';
proc gdevice c=gdevice0.devices nofs;
copy gif from=sashelp.devices newname=gifft;
modify gifft charrec=(1,50,90,'SAS Monospace','y');
run;quit;

Specify DEVICE=GIFFT in the code to be able to use fonts from the FreeType library in the output. After creating the device driver, you can access it whenever the same GDEVICE0 libname is in effect. This means you do not need to rerun the GDEVICE procedure in subsequent SAS sessions, only assign the same LIBNAME statement.

3. Methods

a. File > Export

After generating the graph to the Graph window, resize the window if desired, select the File menu, and then Export or Export as Image.

Choose GIF or BMP as the file type, designate a location and filename, and save the graph.

From an Office document, choose Insert > Picture > from File from the menu, select the graph, and click Insert.

b. Device Driver

The BMP device driver can be used to directly produce BMP output. The output size for this device driver is larger on Windows systems, 15x12in, than on other operating systems, 8.42x6.31in.

For the GIF format, there are several device drivers available:

Table 6. Device Drivers for GIF

Name Default Output Size
GIF 800x600 pixels
GIF733 >733x550 pixels
GIF570 570x430 pixels
GIF373 373x280 pixels
GIF260260x195 pixels
GIF160 160x120 pixels
GIFANIM 1280x1024 pixels (animated GIF output)

You can use these device drivers to create output at different sizes without adjusting the GOPTIONS. Remember that only the GIF and GIF733 device drivers support hardware fonts.

Use a FILENAME statement and a GOPTIONS statement to designate a storage location and device driver. For example:

filename output 'myfile.gif';
goptions device=gif gsfname=output gsfmode=replace;
/* graph procedure goes here */
run;quit;

From an Office document, choose Insert > Picture > From file and select the file you just created.

In Office 2000 and XP, PowerPoint can display animated GIF files when the slide show is running. In Office 97, PowerPoint will only import the first image in an animated GIF file. Microsoft Word will import an animated GIF, but only display all the images if the document is saved as an HTML file.

E. EPS

1. Advantages and Limitations

Encapsulated PostScript files store graphics using the PostScript printer language. This means the images can be a combination of vector and bitmap objects. EPS images can be resized in Microsoft Office but they should not be edited. Because the system display will not use the PostScript language to render the graph, these graphics may only be visible when printed to a PostScript printer.

In addition to the PostScript information in the file, the format can store a preview of the graph as a TIFF or WMF image. This preview can be used to display the graph to the screen or to print the graph to non-PostScript printers. SAS/GRAPH does not include this preview, so EPS files generated from SAS will not display in Microsoft Office 97 or Office 2000, and they cannot be printed to non-PostScript printers. You can add the preview using third-party software. See section III.E.4 for more information.

When you import an EPS file to Office 2002 or a later release, the preview is added automatically. In these releases you will be able see the graph after it is imported and print it to non-PostScript printers. However, you should not resize the graph after it is imported.

Because it uses the PostScript language, the EPS format is a document format capable of storing multiple pages per file. However, the format was designed to contain only one page per file, and properly formatted EPS files should only contain a single page.

2. Fonts

The EPS format can use all 35 standard PostScript fonts. This is the standard font set included with most PostScript printers. Text written in these fonts may appear clearer on the printed output than text in a software font.

Although both methods described below for creating EPS output recognize the same font set, the names of the fonts vary. Be sure to use the correct name for the export method you choose.

The available fonts include:

Table 7-Hardware Font Names for EPS Output

PSLEPSF and PSLEPSFC
Device Drivers
PostScript EPS color and PostScript EPS Gray
Universal Printers
Courier Courier
Courier-Oblique Courier/oblique
Courier-Bold Courier/bold
Courier-BoldOblique Courier/bold/oblique
Times-Roman Times
Times-Italic Times/italic
Times-Bold Times/bold
Times-BoldItalic Times/bold/italic
Helvetica Helvetica
Helvetica-Oblique Helvetica/oblique
Helvetica-Bold Helvetica/bold
Helvetica-BoldOblique Helvetica/bold/oblique
Symbol Symbol
AvantGarde-Book ITC Avant Garde Gothic/book
AvantGarde-Demi ITC Avant Garde Gothic/demi
AvantGarde-BookOblique ITC Avant Garde Gothic/book/oblique
AvantGarde-DemiOblique ITC Avant Garde Gothic/demi/oblique
Palatino-Roman Palatino
Palatino-Bold Palatino/bold
Palatino-Italic Palatino/italic
Palatino-BoldItalic Palatino/bold/italic
NewCenturySchlbk-Roman New Century Schoolbook
NewCenturySchlbk-Bold New Century Schoolbook/bold
NewCenturySchlbk-Italic New Century Schoolbook/italic
NewCenturySchlbk-BoldItalic New Century Schoolbook/bold/italic
Helvetica-Narrow Helvetica Narrow
Helvetica-Narrow-Bold Helvetica Narrow/bold
Helvetica-Narrow-Oblique Helvetica Narrow/oblique
Helvetica-Narrow-BoldOblique Helvetica Narrow/bold/oblique
ZapfChancery-MediumItalic ITC Zapf Chancery/medium/italic
ZapfDingbats ITC Zapf Dingbats
Bookman-Light ITC Bookman/Light
Bookman-Demi ITC Bookman/Demi
Bookman-LightItalic ITC Bookman/Light/Italic
Bookman-DemiItalic ITC Bookman/Demi/Italic

Tables produced in EPS documents created with the Universal Printers can use these same fonts. The fonts must be assigned either by a style sheet referenced on the ODS PRINTER statement, or by specifying the STYLE option inside the procedure itself. For more information, see the discussion about the TEMPLATE procedure in &147;The Complete Guide to the Output Delivery System&148; in the OnlineDoc.

3. Methods

a. Device Driver

There are two recommended EPS device drivers: PSLEPSF for monochrome output and PSLEPSFC for color output.

Use a FILENAME statement and a GOPTIONS statement to designate a storage location and device driver. For example:

filename output 'myfile.eps';
goptions device=pslepsfc gsfname=output gsfmode=replace;
/* graph procedure goes here */
run;quit;

From an Office document, choose Insert > Picture > From file and select the file you just created. Remember the graph will not display in some releases. Instead you will see a text box representing the size of the graph that states a preview was not included with the EPS file. The graph will appear when the output is sent to a PostScript printer. You can add the preview to the file using the instructions in section III.E.4.

b. Universal Printer

EPS output can now be generated using the new EPS Universal Printers. There are two printers available: "PostScript EPS Gray" for grayscale output and "PostScript EPS Color" for color output. This method can be useful for combining multiple graphs on a single page of output. Use the SASPRTC device driver with the ODS PRINTER destination.

On Windows systems you may get a warning that the printer was not found. By default, the ODS PRINTER destination looks for system printers first, then for Universal printers in the SAS registry. When a system printer by the name of "PostScript EPS Color" is not found, a warning is generated, and then the SAS registry is searched. You can prevent this warning by adding the SAS parameter on the ODS PRINTER statement, such as

ods printer sas printer="PostScript EPS Color" file='myfile.eps';

On Windows systems, the SASPRTC device driver also points to the system printers when the LISTING destination is open. For that reason, it is a good practice on Windows systems to close the LISTING destination when writing to another ODS destination that uses this device driver. See the basic syntax in section III.E.3.b.2 below.

1) Page Setup

When creating EPS documents, the page orientation and margins can be controlled from the OPTIONS statement. The available options include ORIENTATION, which takes the values LANDSCAPE or PORTRAIT; and TOPMARGIN, BOTTOMMARGIN, LEFTMARGIN, and RIGHTMARGIN to set the margins on each side. See section IV.E for an example. The OPTIONS statement should be specified before the PRINTER destination is opened.

You can also change the paper size by specifying the PAPERSIZE option on the OPTIONS statement. Valid values include LETTER, ISO A4, and LEGAL. The complete list of predefined sizes is in the SAS Registry under the key [CORE\PRINTING\PAPER SIZES]. In SAS 9.0 and above, you can also define your own custom size using syntax similar to the following:

options papersize=("8 in","6 in");

This option does not work in SAS 8.2, as documented in SAS Note 5913.

2) Basic Syntax

goptions reset=all device=sasprtc;
ods listing close;
ods printer printer="PostScript EPS Color" file='myfile.eps';
/* graph code goes here*/
run;quit;
ods printer close;
ods listing;

3) Combining tabular and graphics output using STARTPAGE

An advantage to using a document format is that text output, such as tables, can be easily combined with graphics output. The general form of the statements is:

goptions reset=all device=sasprtc vsize=5in;
ods listing close;
ods printer printer="PostScript EPS Color"
file='myfile.eps' startpage=never; /* text procedure goes here*/
run;
/* graph procedure goes here*/
run;quit;
ods printer close;
ods listing;

This code would create a one-page EPS document with the table displayed above the graph. The VSIZE is used to restrict the graph height and prevent the graph from overlapping the table.

Please Note: The STARTPAGE parameter recognized by the ODS PRINTER destination cannot be used with the ODS HTML or ODS RTF destinations. Section IV.H contains an example of combining text and graphs in these destinations.

4) Combining tabular and graphics output using ODS LAYOUT--EXPERIMENTAL

With the ODS PRINTER destination in SAS 9.1 you can use the experimental ODS LAYOUT feature to easily combine text and graphs on the same page. The general syntax is:


goptions reset=all device=sasprtc vsize=5in;
ods listing close;
ods printer printer="PostScript EPS Color" file='myfile.eps';
ods layout start;
ods region height=5 in width=7.5 in x=0 in y=0 in;
/* procedure to go on the top half of the page*/
run;quit;
ods region height= 5in width=7.5 in x=0 in y=5 in;
/* procedure to go on the bottom half of the page*/
run;quit;
ods layout end;
ods printer close;
ods listing;

More information about the ODS LAYOUT syntax is available at the following website: http://support.sas.com/rnd/base/topics/odsprinter/new9.html#LAYOUT.

4. Adding a TIFF or WMF Preview

SAS does not include the TIFF or WMF preview in the EPS files it creates. When you import an EPS file to Office 2002 or a later release, the preview is added automatically. For the graph to display in Microsoft Office 97, Office 2000, or to print to non-PostScript printers, you can add this preview using third-party software such as Ghostview.

  1. Install Ghostview from: http://www.cs.wisc.edu/~ghost/index.html
  2. Launch Ghostview and open your EPS file.
  3. Select Edit > Add EPS Preview and choose Windows Metafile.
  4. Save the file.

The preview may be resized but should not be edited. This preview will be printed if the output is printed to a non-PostScript printer. If the output is printed to a PostScript printer, the PostScript information in the file will automatically be used to generate the output.

F. HTML

1. Advantages and Limitations

The Hypertext Markup Language uses standardized tags to describe the layout and style of a document. Graphs are not stored directly in the document, but in external files that the document links to. When the HTML file is opened in Microsoft Word 97, the tables it contains and the graphs it references will be loaded automatically. In PowerPoint 97 and Excel 97, only the tables will be loaded, not the graphs. In Office 2000 and beyond, graphs will also be loaded along with the page when the HTML page is opened in Word, PowerPoint, and Excel.

You can create HTML pages using the WEBFRAME or HTML device drivers, or using the ODS HTML destination. For exporting to Office, the ODS HTML destination is recommended. With this destination you can use GIF, JPEG, PNG, or ActiveX graphics.

ActiveX is a special kind of Windows-based vector graph that stores information needed to create the graph directly in the HTML file. A second component, the graph control, must also be installed on the system where the graph is displayed. The graph control interprets the graph information and displays the graph. If the graph control is not installed or a different version of the graph control is installed on the system, the graph may not display. See "Requirements for Running ActiveX Graphs Locally"for more information.

For additional information on the other graphics formats, see sections IIIC and IIID above.

2. Fonts

Text or tabular output written to an HTML file can use TrueType or PostScript fonts, depending on the operating system. Use the TEMPLATE procedure to set the fonts for the text output. This procedure is discussed in the Base SAS section of the OnlineDoc under "The Complete Guide to the Output Delivery System", in the section entitled "The Template Procedure".

Graphs created with the ODS HTML destination are subject to the restrictions of the particular graphics format used. See the discussions for the GIF, JPEG, and PNG series of device drivers. Because these are raster formats, which fonts the images will use is dependent upon the operating system when the graphs are created, not where they are imported and displayed.

3. Method

The recommended method for creating HTML documents for Microsoft Office is to use the ODS HTML destination.

a. Page Setup

Normally HTML documents acquire their page layout from the application displaying them. Some control over the page layout is available if you create a CSS style sheet. For more information, see " Specifying Dimensions, Orientation, and Margins with the @page Rule" in the "PROC TEMPLATE FAQ".

b. Basic Syntax

The general form for generating ODS HTML output is as follows:

goptions reset=all device=DEVICE;
ods listing close;
ods html body='output.html'path='LOCATION';
/* graph and other procedures go here */
ods html close;
ods listing;

For the DEVICE you can specify JPEG, PNG, one of the GIF series of device drivers, or the ACTIVEX device driver. In this example, the PATH determines the location of both the HTML and graph files. The images will be loaded when the HTML file is opened.

If you are creating an HTML file on a mainframe system, see the section "Alternative ODS HTML Statements for Running Examples in Different Operating Environments" in the Output Delivery System section of the Base SAS Software Reference in the OnlineDoc for information on storing files on this system.

c. Combining tabular and graphics output

An advantage to using a document format is that text output, such as tables, can be easily combined with graphics output. For example, to include a table above the graph in the output, the general form of the statements is:

goptions reset=all device=DEVICE;
ods listing close;
ods html body='body.html' path='LOCATION';
/* text procedure goes here */
run;
/* graph code goes here */
run;quit;
ods html close;
ods listing;

See section IV.H for a complete example.

G. RTF

1. Advantages and Limitations

The RTF format was designed for sharing documents between word processors. This format can easily store both text and graphics output. Of the products in the Microsoft Office suite, only Microsoft Word will import the graphs from files in this format. Microsoft PowerPoint can import the text from an RTF file to make an outline.

Graphics can be stored directly in RTF files in many formats. The ODS RTF destination in SAS can store EMF, JPEG, PNG, or ACTIVEX graphics. ActiveX is a special kind of Windows-based vector graph that stores information needed to create the graph directly in the RTF file. A second component, the graph control, must also be installed on the system so the graph information can be read and the image can be rendered to the display. If the graph control is not installed or a different version of the graph control is installed on the system, the graph may not display. See "Requirements for Running ActiveX Graphs Locally"for more information.

For additional information on the other graphics formats, see sections IIIA and IIIC above.

Be aware that the file size of an RTF document that contains graphs will probably grow if you open and then save the RTFdocument from Word. Microsoft Knowledgebase article Q224663 contains an explanation that includes the following information:

This functionality is by design in Microsoft Word. If an EMF, a PNG, a GIF, or a JPEG graphic is inserted into a Word document, when the document is saved, two copies of the graphic are saved in the document. Graphics are saved in the applicable EMF, PNG, GIF, or JPEG format and are also converted to WMF (Windows Metafile) format.

2. Fonts

Text or tabular output written to an RTF file can use TrueType or PostScript fonts, depending on the operating system. Use the TEMPLATE procedure to set the fonts for the text output. This procedure is discussed in the Base SAS section of the OnlineDoc under "The Complete Guide to the Output Delivery System", in the section entitled "The Template Procedure".

Graphs created with the ODS RTF destination are subject to the restrictions of the particular graphics format used. The SASEMF device driver is used by default. Text stored in this graphics format is restricted to the Courier, Courier New, and Letter Gothic fonts in SAS 8.2 and 9.0. In SAS 9.1, the SASEMF device driver can use the FreeType library to access more fonts. See sections II.C.2 and III.A.3 for more information. Because EMF is a vector format, if the graph is edited, font substitutions may occur if a requested font is not available locally on the recipient's system.

The PNG or JPEG device drivers usually recognize system fonts and, in SAS 9.1, fonts available through the FreeType library. Because these are raster formats, which fonts the images will use is dependent upon the operating system when the graphs are created, not where they are imported and displayed. See section III.C.2 for information on fonts available with these device drivers. In SAS 8.2, to control the fonts in the graph, you should set both a DEVICE and a TARGET on the GOPTIONS statement. See the example in section IV.D.

3. Method

RTF documents containing graphs can only be created from SAS using the ODS RTF destination.

When creating RTF files, the format for the graphics is set using the DEVICE on the GOPTIONS statement, and the document itself is designated using the ODS RTF statement. If no graphics device driver is specified, EMF graphs will be created with the SASEMF device driver by default.

a. Page Setup

When creating RTF documents, the page orientation and margins can be controlled from the OPTIONS statement. The available options include ORIENTATION, which can be LANDSCAPE or PORTRAIT, and TOPMARGIN, BOTTOMMARGIN, LEFTMARGIN, and RIGHTMARGIN. See section >IV.E for an example.

For ODS RTF to recognize the margins set by the OPTIONS statement in SAS 8.2, you may also need to specify STYLE=PRINTER on the ODS RTF statement, as documented in SAS Note 5468. Alternately, you could define the margins in your own style sheet using the TEMPLATE procedure. See section IV.F for an example.

Be aware that the RTF destination also reserves .25 inches for a header and footer at the top and bottom of the page, respectively. These sizes cannot be adjusted by SAS at this time. When defining the margins, you may want to subtract .25 in from the top and bottom margins to get the expected page size. In SAS 8.2, the paper size may be incorrect when the margins are specified. See SAS Note 005472 for more information.

You can change the paper size by specifying the PAPERSIZE option on the OPTIONS statement. Valid values include LETTER, ISO A4, and LEGAL. The complete list of predefined sizes is in the SAS Registry under the key [CORE\PRINTING\PAPER SIZES]. You can also define your own custom size using syntax similar to the following:

options papersize=("8 in","6 in");

b. Basic Syntax

The basic syntax is as follows:

goptions reset=all;
ods listing close;
ods rtf file='myfile.rtf';
/* graph code goes here */
run;quit;
ods rtf close;
ods listing;

From Microsoft Word, choose File > Open and select the RTF file you just created. All the tables and graphs contained in the file will be imported together.

In SAS 8.2, to control the graph size and fonts, you should set both a DEVICE and a TARGET on the GOPTIONS statement. See example IV.D for an example.

c. Combining tabular and graphics output

An advantage to using a document format is that text output, such as tables, can be easily combined with graphics output. The general form of the statements is:

goptions reset=all;
ods listing close;
ods rtf file='myfile.rtf';
/* graph code goes here */
run;quit;
/* text procedure goes here */
run;
ods rtf close;
ods listing;

This code would create a two-page RTF document. The first page would contain the graph, the second the table. See section IV.H for an example.

IV. Examples

These examples use FILENAME and GOPTIONS statement settings that work well for Windows systems. Section IV.I below shows what options may be used for these statements on other operating systems. The Companion documentation for each host contains additional information about GOPTIONS and FILENAME statement parameters.

Some of these examples use device drivers that recognize system fonts. Currently TrueType fonts have been specified with these device drivers in the example code. You may need to specify different system fonts or software fonts if you are running these examples on a non-Windows system. If you are running SAS 9.1, you may be able to reference the same TrueType font if you have used the FONTREG procedure to registry the font with SAS, and modified the device driver if necessary.

The following sample data can be used for all the examples.

data Sample; do Location='Atlanta','Raleigh','Denver'; do Quarter=1 to 4; Sales=ceil(ranuni(0)*100);
output;
end;
end;
run;

A. Creating a full-size EMF graph

The following code exports an 8inx10in GCHART directly to an EMF file named LOCATION_SALES.EMF in the C:\GRAPHS directory. The Courier New font is used for all text in the output.

goptions reset=all device=emf hsize=8 in vsize=10 in ftext="Courier New" htext=14pt
gsfname=output gsfmode=replace;
filename output 'c:\graphs\Location_Sales.emf';
proc gchart data=sample; vbar3d location / sumvar=sales width=20 patternid=midpoint shape=star; run;quit;

On non-Windows systems, you need to specify XMAX=8in and YMAX=10in instead of HSIZE and VSIZE. The default outputfor the EMF device driver is smaller on these systems.

Note: When imported to Microsoft Word, the image will retain its size (8x10in) if the margins of the document allow for it. You may need to resize the document margins before importing the graph to retain the full size, or you can adjust the margins and graph size after import.

B. Creating a CGM file containing multiple graphs

The following code creates a CGM file using the Helvetica font for all text. The file will contain three landscaped images, one for each value of LOCATION in the data. The file is named LOCATION.CGM and stored in the C:\GRAPHS directory. The example uses the CGMOFML device driver that was introduced in SAS 9.0. If you are running SAS 8.2, you should specify the CGMOF97L device driver instead.

goptions reset=all device=cgmofml ftext="Helvetica" gsfname=output gsfmode=replace; filename output 'c:\graphs\location.cgm';
proc sort data=sample;
by location;
run;
symbol1 v=dot interpol=sm;
proc gplot data=sample uniform;
by location; plot sales*quarter; run;quit;

Because all the images are produced by one procedure, the GSFMODE of REPLACE can be used. With this setting, the images are appended automatically to the same file, but if a previous version of the file exists, it is replaced. Refer to section III.B.5.d for information on importing multiple pictures from a single CGM file into Microsoft Office.

C. Creating High Resolution JPEG, PNG, or TIFF output

This code creates a PNG file with 600 pixels per inch named SALES.PNG in the C:\GRAPHS directory. The resolution is adjusted directly on the GOPTIONS statement. See also section III.C.4 about creating a high resolution device driver.

goptions reset=all device=png ftext="Arial" htext=12pt lfactor=6 gsfname=output gsfmode=replace hpos=70
xmax=6 in ymax=4 in xpixels=3600 ypixels=2400;
filename output 'c:\graphs\sales.png';
proc gchart data=sample; vbar quarter / group=location sumvar=sales patternid=group; run;quit;

The ratio of pixels-to-inches sets the resolution to 600ppi: 6x600=3600, 4x600=2400. Because increasing the resolution increases the file size, it is recommended that the resolution of the image not exceed that of the output device or printer. When changing the resolution of the output, it is important that the XMAX and YMAX parameters be used rather than HSIZE and VSIZE.

Because the resolution of the image was increased by a factor of 6, the LFACTOR option was increased by a factor of 6. Otherwise the lines may appear too thin in the enhanced image. You may also want to explicitly set the height of the text using the HTEXT= option as shown. Also see creating a new device driver at a specific resolution.

D. Changing the attributes of the graphs within RTF documents

In SAS 8.2, to effectively control the size of the graphs in ODS RTF output, it is generally recommended that the GOPTIONS statement include the same device driver for both a DEVICE and a TARGET. The TARGET specification is not necessary in SAS 9.0 and beyond. XMAX and YMAX are used to set the graph size larger than the default allowable size for the PNG device driver:

goptions reset=all device=png target=png xmax=7 in ymax=9 in ftext="Arial"; ods listing close;
options orientation=portrait;
ods rtf file='c:\graphs\salespie.rtf';
proc gchart data=sample; pie location / sumvar=sales percent=inside;
run;quit;
ods rtf close;
ods listing;

In this example, a single PNG graph will be created that is 7x9 inches. Notice space was reserved for the header and footer in Word.

E. Changing the page layout for ODS PRINTER or ODS RTF output using the OPTIONS statement

To control the page orientation and margins in ODS PRINTER or ODS RTF output, use the ORIENTATION parameter and the series of margin parameters on the OPTIONS statement. The OPTIONS statement should precede the ODS PRINTER or ODS RTF statement that defines the output file. For example, the following code creates an EPS file in landscape orientation with a one-and-a-half inch margin on the top and one inch margins on all other sides.

options orientation=landscape topmargin=1.5 bottommargin=1 leftmargin=1 rightmargin=1 ; goptions reset=all device=sasprtc border;
ods listing close;
ods printer sas printer='PostScript EPS Color' file='c:\graphs\VerticalBar.eps'; proc gchart data=sample; vbar3d quarter / sumvar=sales discrete shape=cylinder; run;quit; ods printer close;
ods listing;

Remember for the RTF file, the top and bottom margins will add .25 in. An RTF file created with these settings would have a top margin of 1.75 in and a bottom margin of 1.25 in.

F. Changing the margins for ODS PRINTER or ODS RTF output using the TEMPLATE procedure

To control the page orientation and margins in ODS PRINTER or ODS RTF output, you can define a new style sheet using the TEMPLATE procedure. You must then reference the style sheet in the ODS PRINTER or ODS RTF statement. For example, the following code creates an RTF file with a one inch margins on all sides.

ods path sasuser.templt(update) sashelp.tmplmst(read);
proc template; define style mystyle;
parent=styles.rtf; style body from document / topmargin=.75 in leftmargin=1 in
rightmargin=1 in bottommargin=.75 in;
end;
run;
goptions reset=all hsize=5 vsize=6 ftext="Courier" dev=sasemf target=sasemf htext=12pt;
ods listing close;
ods rtf file='c:\graphs\VerticalBar.rtf' style=mystyle; proc gchart data=sample; vbar3d quarter / sumvar=sales discrete shape=cylinder patternid=midpoint; run;quit; ods rtf close;
ods listing;

Remember for the RTF file, the header and footer margins will add .25 in to the top and bottom margins, respectively. For an EPS file, specify TOPMARGIN=1 IN and BOTTOMMARGIN=1 IN instead.

It is important to specify the units of inches (IN) or centimeters (CM) when defining the margins using a style sheet.

G. Combining graphs in a single graphics file using GREPLAY

The following code combines four graphs in the same 8x10in EMF file using the GREPLAY procedure. The file is written to the QTRLOCSALES.EMF in the C:\GRAPHS directory. This method for combining multiple graphs in a single image works with any of the SAS/GRAPH device drivers.

/* Clear the graphics catalog; not necessary in a batch session */
proc greplay igout=temp nofs; delete _all_; run;quit;
/* Create the graphs using all the desired GOPTIONS.
Use NODISPLAY to write the graphs only to the
catalog designated on the GOUT parameter and
not the file. Notice the HSIZE and VSIZE are reduced to
fit the graph in the panels. On non-Windows systems, use XMAX and YMAX instead. */
goptions reset=all device=emf hsize=4 in vsize=5 in nodisplay ftext="Arial" gsfname=output gsfmode=replace; filename output 'c:\graphs\QtrLocSales.emf';
proc sort data=sample;
by quarter;
run;
proc gchart data=sample gout=temp;
by quarter; vbar location / sumvar=sales width=15 patternid=midpoint; run;quit;
/* Set DISPLAY and use GREPLAY to create the
combined graph. Set the HSIZE and VSIZE to the
full size. */
goptions display hsize=8 in vsize=10 in;
proc greplay igout=temp nofs tc=sashelp.templt; template l2r2;
treplay 1:gchart 2:gchart1 3:gchart2 4:gchart3;
run;quit;

The single EMF file, C:\GRAPHS\QTRLOCSALES.EMF, contains the four graphs. They will be imported as a single image to the same page or slide in Microsoft Office.

H. Combing text and graphics output with ODS HTML or ODS RTF

With the ODS HTML and ODS RTF destinations, output from text and graphics procedures can be combined in the same document. For example:

goptions reset=all;
ods listing close;
ods rtf file='c:\graphs\Plot.rtf'; proc print data=sample;
run;
symbol1 i=join;
proc gplot data=sample; plot sales*quarter=location; run;quit;
ods rtf close;
ods listing;

In this example, the table will appear on the first page and the graph on the next page. With the ODS RTF destination, you can specify STARTPAGE=NO to remove the automatic page breaks between each output. With the ODS HTML destination, you need to modify the style sheet to remove the automatic horizontal line and printed page break. For example:

ods path sasuser.tmplmst(update) sashelp.tmplmst(read);
proc template; define style noline;
parent=styles.default; style body from body / pagebreakhtml=_undef_; end;
run;

Reference this new style, NOLINE, on the ODS HTML statement.

I. Sample statements for non-Windows systems

The examples above each use FILENAME, GOPTIONS, and ODS statements that are valid on Windows systems. Below are examples of alternative FILENAME and ODS statements for Unix and MVS operating systems. If your mainframe system uses HFS, your statements would be similar to that for Unix. If your mainframe is not using HFS, use the statements listed under MVS. You must have write authority to these locations in order to create the files.

1. Unix and HFS Mainframe Systems

a. Create a single file:

The following FILENAME statement would create a file called GRAPH.GIF in the local directory.

goptions device=gif gsfname=output;
filename output "graph.gif"

b. Create many files in a directory:

The following FILENAME statement would create GIF files to the MYGRAPHS subdirectory under the current directory.

goptions dev=GIF gsfname=output;
filename output "/mygraphs"

Remember in SAS 9.1 you must use the NOFILEONLY option when writing multiple EMF, PNG, or JPEG files using an aggregate storage location. See SAS Note 13115 for more information.

c. Create a document:

The following code would create the HTML file BODY.HTML and PNG files in the OUTPUT subdirectory under the current directory.

goptions dev=png;
ods html body='body.html' path="/output";

2. MVS Systems:

>

Prior to SAS 9.1, you cannot create JPEG, PNG, or TIFF files when writing to a sequential file. You will receive an error, "Random access not allowed", as documented in SAS Note 1761. The problem also occurs when using the JPEG or PNG device drivers with ODS RTF. On theses systems, the GIF format is recommended instead for individual files, and SASEMF is recommended for use with RTF.

a. Create a single file:

The following code creates a CGM file named TEST.CGM in the current user's directory.

goptions reset=all dev=cgmof97l gsfname=fileref gsfmode=replace gsflen=80 gprotocol=sasgpasc; filename fileref 'userid.test.cgm' disp=(new,catlg) recfm=vb lrecl=137 dsorg=ps;

b. Create many files in a directory:

You can create multiple graph members of the same PDSE as follows:

goptions dev=gif gsfname=output gsflen=80 gprotocol=sasgpasc;
filename output 'userid.my.graphs' disp=(new,catlg) recfm=vb lrecl=137 dsorg=ps;

For exapmle, GPLOT output would become USERID.MY.GRAPHS(GPLOT). When transporting the file to another system, be sure to include the appropriate extension for the file name.

c. Create a document:

The following code creates an ASCII HTML file named EXAMPLE.HTM.BODY. When the file is transferred to the ASCII system, it will be named BODY.HTML.

goptions dev=gif;
filename pdsehtml '.example.htm' dsntype=library dsorg=po disp=(new, catlg, delete); ods html body='body' (url='body.html') path='.example.htm'(url=none) trantab=ascii;

Also see the following resources:

16FEB05