Exporting SAS/Graph Plots to Other Applications


Plots produced with SAS/GRAPH can be used in other Windows applications in two basic ways: One common format for graphics files understood by many Windows applications is the Computer Graphics Metafile (CGM) format. This note describes how to produce CGM files which can be used with WordPerfect 6.1. Some of the information below was taken from SAS Institute's Technote ts252s.ps. Similar procedures can be used with Harvard Graphics, Word, and other Windows applications.

Creating CGM files

You can create CGM files for exporting to other packages by using one of the CGMxx device drivers in a GOPTIONS statement. The name of the output file is specified in a FILENAME statement, as shown below.
    GOPTIONS DEVICE=CGMxx GSFNAME=fileref GSFMODE=REPLACE;
    FILENAME fileref  'drive:\directory\filename.ext';

Substitute the name of one of the CGM drivers for CGMxx. WordPerfect drivers include:

CGMWP61P
Word Perfect 6.1, portrait mode (8.5 wide by 11in high)
CGMWP61L
Word Perfect 6.1, landscape mode (11 wide by 8.5in high)
CGMWPWA
Word Perfect generic driver
Notes:
  1. The CGMWP61L and CGMWP61P drivers are not part of the standard set of device drivers shipped with SAS 6.10 for Windows. These drivers were created following the instructions in Technote ts252s.ps, and installed on Pavlov.
  2. If you are creating the CGM file on a non-PC host, you must do a binary download of the CGM file. A text download will not work.

Example

This example produces two plots which are directed to separate CGM files. Note that (a) each plot must be produced in a separate GPLOT step, and (b) the filename statement must be used before each graph is produced to associate a new filename with the fileref 'graph'.
data wiggle;
   do x=1 to 20 by .2;
      y1 = x + sin(5*x) + normal(0);
      y2 = 10 - (x/2) + sin(3*x);
      output;
      end;

goptions device=cgmwp61p gsfname=graphs gsfmode=replace;
filename graph  'a:\sasuser\graphs\wiggle1.cgm';
proc gplot data=wiggle;
    plot y1 * x = 1;
run;

filename graph  'a:\sasuser\graphs\wiggle2.cgm';
proc gplot data=wiggle;
    plot y2 * x = 2;

The GRAPHOUT macro

A SAS macro program, GRAPHOUT, greatly simplifies the process of creating CGM (and other external graphics) files. The program uses the GREPLAY procedure to replay any or all of the graphs previously generated in your SAS session, saving each one to an individual CGM file.
 %graphout(
        device=cgmwp61p,
        name=sas,
        ext=cgm,
        catalog=gseg,
        first=1,
        last=0);
Each graph from the catalog is output to a separate file in the current directory. The files are named sequentially, prefixed with the value of the name parameter, e.g., sas1.cgm, sas2.cgm, ...
device=cgmwp61p
Graphics device to be used (the default is WordPerfect6.1, portrait mode). Some other possibilities:
cgmwp61L- WordPerfect 6.1, landscape;
cgmwpwa - WordPerfect, Windows;
cgmhg3a - Harvard Graphics;
cgmmw6c - Microsoft Word 6.0 (color)
name=sas
Base name for output files (serial number is added)
ext=
File name extension for output files. The appropriate extension is used by default if the DEVICE driver contains 'CGM', 'EPS', 'PS', 'GIF', 'WMF' or 'JPEG'. Otherwise, the default extension is 'GRF'.
OUTDIR=
Output directory for output files. [Default: current directory]
catalog=gseg
Catalog containing the graphs (gseg is SAS default)
first=1
The sequence umber of first graph to plot in the graphic catalog to be plotted. >0 means absolute number of first graph, <1 means number of first graph relative to last (i.e. 0 means last graph only, -1 means first is one before last, etc.)
last=0
Number of last graph to plot >0 means absolute number of last graph, <1 means number of last graph relative to number of graphs in the catalog (i.e. 0 means last graph in the catalog, -1 means one before last, etc.)

Example

This example produces two plots which are viewed first on the screen. After the PROC GPLOT step, the %graphout statement causes the last two plots in the GSEG graphics catalog to be written to separate files, wiggle1.cgm, and wiggle2.cgm in the current directory.

Note that the GOPTIONS and SYMBOL statements specify hardware fonts for text and plotting symbols (see below).

data wiggle;
   do x=1 to 20 by .2;
      y1 = x + sin(5*x) + normal(0);
      y2 = 10 - (x/2) + sin(3*x);
      output;
      end;
goptions ftext=HWCGM001;
proc gplot data=wiggle;
   plot y1 * x = 1;
   plot y2 * x = 2;
   symbol1 c=black f=hwcgm006 v=#;   *-- charting symbol;
   symbol2 c=black f=hwcgm012 v=z;   *-- ZapfDingBats symbol;
run;

%graphout(name=wiggle, first=-1);

Importing CGM files into WordPerfect 6.1

Once you have created the CGM files, you can import them into WordPerfect for Windows (and Presentations for Windows) by doing the following:
  1. Select Graphics ==> Image, which will bring up a Insert Image window You can also select the Diamond found on the right side of the top button bar. If you are in Presentations select File ==> Open to invoke the same menu.
  2. Select the List Files of Type pulldown and select CGM files or All Files
  3. You can select the View button to view your graph before it is imported.
  4. Select OK and the graph will be placed into the page as a very small image. You can stretch the image to any size and place the graph anywhere on the page after the graph is imported.
  5. Clicking with your right mouse button will bring up an editing menu. You can also click on the Graphics ==> Edit box to invoke a menu to bring up a tools menu at the lower most position of the top menu bar.
  6. Double clicking with your left mouse button will place the graph into Presentations if Novell Presentations is installed; otherwise it will place the graph into WPDraw.

Tips

Use Hardware fonts

WordPerfect can import a picture of any size. However larger CGM files may take longer to import and convert to WordPerfect images. This problem is especially likely to occur if you are using filled software fonts, such as SWISS, ZAPF, etc. Text that is created with these fonts will be harder to manipulate in WordPerfect or Presentations because the text will be a series of moves and draws or a series of polygons.

If possible, you should use hardware fonts for text because it is easier to manipulate. You can reduce the size of your CGM file by using hardware fonts and avoiding SAS filled fonts, such as SWISS, ZAPF, etc. The CGMWP61x device drivers can use equivalent hardware fonts that generate much less space and import into WordPerfect faster. In addition, the text strings generated by these hardware fonts can be manipulated as hardware text strings so they can be moved and sized much more easily.

For example, if you want to use the Arial Bold font, you would specify F=HWCGM002, where HWCGM002 refers to the 2nd font listed below. There are 12 fonts available with the CGMWP61x device drivers. If you do not specify a font, SAS/GRAPH will use an Arial font. Any hardware text string that is imported can be changed to any font installed on your system after the graph is installed in WordPerfect.

SAS Font NameWordPerfect Font
HWCGM001 Arial
HWCGM002 Arial Bold
HWCGM003 ArialItalic
HWCGM004 AvantGarde
HWCGM005 Braggadocio
HWCGM006 (charting font)
HWCGM007 Courier
HWCGM008 Humans521
HWCGM009 Impact
HWCGM010 (symbols font)
HWCGM011 TimesRoman
HWCGM012 (zapf dingbats)

Use FILLINC for polygon-fills

Solid polygon fills produced by the AREAS= option in PROC GPLOT can also create a very large CGM file. Increasing the fill increment by using the FILLINC= graphics option will vastly reduce the size of the CGM file. In some cases a FILLINC= value as high as 40 can be used, depending on the output device. If you increase the FILLINC= value to greater than 20, using hardware text is strongly recommended because polygon fonts such as SWISS may not be fully filled. Certain polygons will have rounded corners, depending on the polygon that is interpreted by WordPerfect. This is caused by problems in the WordPerfect CGM interpreter.

Tips on Using the Draw Tools in Word Perfect 6.1

Manipulating individual objects

CGM images can be fully manipulated once they are imported into WordPerfect or Presentations . The image objects will be ungrouped by default. You can use the Graphics ==> GROUP or the Graphics ==> COMBINE tools found on the top tool bar in Presents to group the objects.

Moving objects

To move an object, place the cursor on the object edge away from the square object handles, or inside the object. Click with the left mouse button and move it to the appropriate area. Do not release the left mouse button until you have moved the object. Otherwise, the object will be selected but you will not be able to move it.

Text handling

You can change the font of any hardware text string by selecting the Format ** Font menu from the top tool bar. This will bring up a font formatting menu in which you can change the text font, height, style and color.

The following table translates SAS/GRAPH heights to point sizes in WordPerfect, (Arial Font assumed, other fonts will be similar).

Cell Height
in SAS/GRAPH
Point size
in WordPerfect
H=0.5 7.0
H=1.0 14.0
H=1.5 22.0
H=2.0 29.0
H=2.5 37.0
H=3.0 44.0
H=3.5 51.0
H=4.0 59.0

Backgrounds

The CGMWP61L and CGMWP61P drivers use a white background by default. You may change the background color by specifying the GOPTIONS CBACK= when the graph is created in SAS/GRAPH.
Author Michael Friendly
Email<friendly@yorku.ca>
Created: Friday, February 16, 1996 Last Updated: Monday, February 19, 1996