Generating Output with SAS/GRAPH Procedures

Overview of Generating Output

ODS provides many destinations to which you can send output. Some of the most often used destinations are HTML (a Web page), LISTING, RTF (Rich Text Format), and PDF (Portable Document Format). The topics that follow show the default output for each of these destinations.
Each ODS destination is associated with a default style and a default SAS/GRAPH device to optimize your output for that destination. For more information, see Introduction to Devices, ODS Destinations, and ODS Styles.
The rules change when you are running SAS without a terminal. In this case you must either specify the DEVICE= option in the GOPTIONS statement or specify the DEVICE= or PRINTER= option in the ODS destination statement. You will not have a terminal associated with your SAS session if you are running in batch mode on z/OS. This is also true if you are running SAS on UNIX without an X Server or if you have specified the NOTERMINAL system option. See the global option DEVICE, and Using Graphics Devices for more information.

Sending Output to the GRAPH Window (LISTING Destination)

When working in an interactive environment such as Windows, the default LISTING destination is the GRAPH window. Use the ODS destination statement at the beginning and end of the SAS program to open and close the LISTING destination, respectively. The following example is a simple GCHART program that produces the output shown in LISTING Destination Output Using the LISTING Style (Shown in the GRAPH Window).
ods html close;
ods listing;
goptions reset=all border hsize=6 vsize=4.5;
title "US Electric Power - Revenue and Generation Sources";
proc gchart data=sashelp.electric (where=(year >= 2000)) ;
  vbar year / discrete sumvar=Revenue subgroup=Customer;
run;
quit;
ods listing close;
LISTING Destination Output Using the LISTING Style (Shown in the GRAPH Window)
LISTING Destination Output Using the LISTING Style (Shown in the GRAPH Window)
The default style applied to output sent to the LISTING destination is LISTING in a Display Manager Session and in batch mode. When you send output to the LISTING destination, SAS/GRAPH uses a default device driver that generates output for the GRAPH window. This device driver does not write an image file to disk.(footnote1) For the LISTING destination, the default device driver varies by operating environment. In a Display Manager Session, the default device driver on Windows systems is WIN. On UNIX systems, the default device driver is XCOLOR, and on z/OS systems, the default device driver is IBMPCGX.

Sending Output to a File

To send output to disk file, send your output to the ODS LISTING destination, but specify a graphics output device using the DEVICE= graphics option. You can use a FILENAME statement and the GSFNAME= graphics option to specify a name and location for the graphics output file. You might choose not to specify a name with the GSFNAME= graphics option. In this case the default name for the procedure or the name specified with the NAME= option is used as the filename.
To create a GIF file with the graph shown in LISTING Destination Output Using the LISTING Style (Shown in the GRAPH Window), in the procedure code, add a FILENAME statement to create a file reference to the desired output file. Then, add the DEVICE=GIF and GSFNAME=FileRef graphics options to the GOPTIONS statement, where FileRef is the file reference that you created in the FILENAME statement.
ods html close;
ods listing;
goptions reset=all border hsize=6 vsize=4.5;
filename gout "./revgensrcs.gif";
goptions reset=all device=gif gsfname=gout border;
title  "US Electric Power - Revenue and Generation Sources";

proc gchart data=sashelp.electric (where=(year >= 2000)) ;
   vbar year / discrete sumvar=Revenue subgroup=Customer;
run;
quit;

ods listing close;
The LISTING style is applied to the graph as shown in LISTING Destination Output Using the LISTING Style (Shown in the GRAPH Window). In the FILENAME statement, the current directory is the default SAS output directory.
For more information about sending graphics output to a file, see Controlling Where Your Output Is Stored .

Sending Output to a Web Page

To send output to a Web page, you simply submit your SAS program that sends your output to the HTML destination, which by default is open. No ODS destination statements need to be specified.
To specify Web page output with a style other than the default style of HTMLBlue, you will need to specify the ODS HTML destination statement with the STYLE= option. To revert back to the default style at the end of the program, specify an ODS HTML destination statement with the STYLE= option to indicate HTMLBlue.
To create a Web page using the style of Default with the graph shown in LISTING Destination Output Using the LISTING Style (Shown in the GRAPH Window), add the ODS HTML statements around the procedure code and submit the following SAS program:
ods html style=default;
goptions reset=all border;
title  "US Electric Power - Revenue and Generation Sources";

proc gchart data=sashelp.electric (where=(year >= 2000)) ;
   vbar year / discrete sumvar=Revenue subgroup=Customer;
run;
quit;

ods html style=HTMLBlue;
HTML Destination Output Using the Default Style (Styles.Default)
HTML Destination Output Using the Default Style (Styles.Default)
By default, SAS/GRAPH creates a PNG file that contains the graph and an HTML page that references the PNG file. You can use the BODY= and PATH= options in the ODS HTML statement to specify a specific filename and location for the HTML and PNG files. SAS/GRAPH displays the HTML page in the Results Viewer. You can also view the graph outside of your SAS session by displaying the HTML page in your browser. The default device driver is PNG, and the default style is HTMLBlue.

Sending Output to an RTF File

To send output to an RTF file, send your output to the RTF destination by specifying the ODS RTF statement. This statement opens the RTF destination so that it can receive output. You must also close the RTF destination before output can be generated.
To create an RTF document that contains the graph shown in LISTING Destination Output Using the LISTING Style (Shown in the GRAPH Window), add the ODS RTF statements around the procedure code and submit the following SAS program. To conserve system resources, close the default HTML destination with another ODS destination statement.
ods html close;
ods rtf;
goptions reset=all border;
title  "US Electric Power - Revenue and Generation Sources";

proc gchart data=sashelp.electric (where=(year >= 2000)) ;
   vbar year / discrete sumvar=Revenue subgroup=Customer;
run;
quit;
ods rtf close;
RTF Output Using the RTF Style
RTF Output Using the RTF Style
By default, SAS/GRAPH creates an RTF file with the graph embedded in it and displays this RTF file in the Results Viewer. When you send output to the RTF destination, SAS/GRAPH does not write a separate image file to disk. The default device driver is the SASEMF driver, and the default style is RTF.

Sending Output to a PDF File

To send output to a PDF file, send your output to the PDF destination by specifying the ODS PDF statement. This statement opens the PDF destination so that it can receive output. You must also close the PDF destination before output can be generated.
To create a PDF document that contains the graph shown in LISTING Destination Output Using the LISTING Style (Shown in the GRAPH Window), add the ODS PDF statements around the procedure code and submit the following SAS program:
ods html close;
ods pdf;
goptions reset=all border;
title  "US Electric Power - Revenue and Generation Sources";

proc gchart data=sashelp.electric (where=(year >= 2000)) ;
   vbar year / discrete sumvar=Revenue subgroup=Customer;
run;
quit;
ods pdf close;
PDF Output Using the Printer Style
PDF Output Using the Printer Style
By default, SAS/GRAPH creates a PDF file and displays this PDF file in the Results Viewer. When you send output to the PDF destination, SAS/GRAPH does not write a separate image file to disk. The default device driver is the SASPRTC device driver, and the default style applied to output sent to the PDF destination is Printer.
FOOTNOTE 1:SAS/GRAPH procedures create GRSEG catalog entries when you send output to the LISTING destination, but the GRSEG file format is an internal file format specific to SAS/GRAPH. It cannot be used as if it were an image file such as a PNG, GIF, or JPEG file. [return]