TS-674An Introduction to Exporting SAS/Graph Output to Microsoft Office SAS Release 8.2 and higherThis 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.
I. IntroductionSAS/GRAPH can export to many of the different graphics file formats that Microsoft Office can import. These include:
◈ EMF Enhanced Windows Metafile 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 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 FormatA. Can the Image Be Edited? - Vector and Raster FormatsThe 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 ResolutionRaster 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. Fonts1. Hardware vs. SoftwareFor 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 LibraryA 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:
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 FontsThe 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:
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 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:
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.
c. Listing Fonts Available Through FreeType
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 AttributesSoftware 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 SizeEach 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:
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 File1. Graphics formats vs. document formatsMost 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. 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 filesThe 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 filesIn 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 OutputThe specific requirements for creating output in each format are described in separate sections below. A. EMF and WMF1. Advantages and LimitationsThe 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 DriversThe 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
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. FontsBecause 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.
Table 2: Comparison of Fonts Available with the EMF and SASEMF device drivers
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. MethodsYou 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)
b.
c. Device driver (all operating systems)
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. CGMThe CGM format is a cross-platform graphics format capable of storing multiple images per file. 1. Advantages and LimitationsGraphs 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 DriversBecause 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.
3. FontsBy default, the Microsoft Office CGM import filter recognizes the Base 14 PostScript fonts as hardware fonts. These fonts include: Table 3: CGM Hardware Fonts
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
The CGM device drivers do not use fonts from the FreeType library. 4. MethodCGM 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:
From an Office document, choose 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 Restrictionsa. 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:
Office 2000 and Office XP:
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.
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:
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:
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, TIFF1. Advantages and LimitationsJPEG, 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. FontsThese 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.
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:
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. MethodsAfter generating the graph to the Graph window, resize the
window if desired and then select the From an Office document, choose 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
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:
From an Office document, choose 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. JPEG and PNG graphics can also be used for RTF output. See section III.G for more information. 4. Changing the Resolution of the OutputIn 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:
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.
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:
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 BMP1. Advantages and LimitationsThe 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. FontsThe 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:
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. Methodsa.File > Export
After generating the graph to the Graph window, resize the
window if desired, select the Choose GIF or BMP as the file type, designate a location and filename, and save the graph. From an Office document, choose 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
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:
From an Office document, choose 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. EPS1. Advantages and LimitationsEncapsulated 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. FontsThe 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
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. MethodsThere 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:
From an Office document, choose 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
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.
This option does not work in SAS 8.2, as documented in SAS Note 5913.
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:
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:
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 PreviewSAS 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.
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. HTML1. Advantages and LimitationsThe 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. FontsText 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. MethodThe recommended method for creating HTML documents for Microsoft Office is to use the ODS HTML destination. a. Page SetupNormally 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 SyntaxThe general form for generating ODS HTML output is as follows:
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 outputAn 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:
See section IV.H for a complete example. G. RTF1. Advantages and LimitationsThe 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. FontsText 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".
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. MethodRTF 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. 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:
The basic syntax is as follows:
From Microsoft Word, choose 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:
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. ExamplesThese 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;
A. Creating a full-size EMF graph
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 graphsThe 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.
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 outputThis 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.
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 documentsIn 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:
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 statementTo 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.
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 procedureTo 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.
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 GREPLAYThe 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.
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 RTFWith the ODS HTML and ODS RTF destinations, output from text and graphics procedures can be combined in the same document. For example:
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:
Reference this new style, NOLINE, on the ODS HTML statement. I. Sample statements for non-Windows systemsThe 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 SystemsThe following FILENAME statement would create a file called GRAPH.GIF in the local directory.
b. Create many files in a directory: The following FILENAME statement would create GIF files to the MYGRAPHS subdirectory under the current directory.
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. The following code would create the HTML file BODY.HTML and PNG files in the OUTPUT subdirectory under the current directory.
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. 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
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;
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. 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;
Also see the following resources: 16FEB05 |