Controlling Where Your Output Is Stored

About the ODS Default Output Directory

With the exception of the ODS HTML destination, by default, ODS output is stored in the current SAS output directory, which is displayed on the status bar of the SAS window. A special case applies to the ODS HTML destination. When you start a new SAS session, the ODS HTML destination is open by default. This initial instance of the ODS HTML destination sends its output to the SAS WORK directory instead of the current directory. To find the path to the WORK directory, in the SAS Explorer window, you can right-click Work in the Libraries folder, and then select Properties from the pop-up menu.
When you close the initial instance of the ODS HTML destination and open a new instance, the output of the new instance and all other instances that are opened in that SAS session is sent to the current directory instead of the WORK directory. It is important that you keep this behavior in mind so that you can locate your ODS output, especially when using the ODS HTML destination.

Specifying the Name and Location of Your ODS Output

You can use the FILE= option in your ODS statement to specify where your ODS output files are stored. For the HTML destination, you can also use the PATH=, GPATH=, and the BODY= options to specify a different location for the HTML output file and the graphics output files. Here is an example that uses the FILE= ODS option with the PDF destination to send the PDF output to file mygraph.pdf in the default SAS directory.
goptions reset=all;
ods html close;
ods pdf style=money file="mygraph.pdf";
proc gchart data=sashelp.prdsale;
   vbar Product / sumvar=actual;
      title1 "First Quarter Sales in Canada";
      where Quarter=1 and Country="CANADA";
   run;
quit;
ods pdf close;
ods html;
Here is an example that uses the PATH=, GPATH=, and the BODY= ODS options with the HTML destination to send the HTML output to file mygraph.html in the current directory, and the graphics output file to the images subdirectory.
goptions reset=all;
ods html style=banker path="./" gpath="images" body="mygraph.html";
proc gchart data=sashelp.prdsale;
   vbar Product / sumvar=actual;
      title1 "First Quarter Sales in Canada";
      where Quarter=1 and Country="CANADA";
   run;
quit;
ods html close;
ods html;
For more information about the PATH=, GPATH=, and BODY= options, see SAS Output Delivery System: User's Guide .

Specifying the Name and Location of Your Graphics Output File

When you use the ODS LISTING destination, you can use the GSFNAME= graphics option to send your output to a graphics output file that you specify. The GSFNAME= option requires a FILENAME statement that creates a file reference that points to a file or an aggregate file storage location. The syntax of the FILENAME statement is as follows:
FILENAME RefName 
"DirectoryOrFile"
If the file reference points to an aggregate file storage location, the graphics output files are named according to the NAME= option, if specified, or the default naming convention. If the file reference points to a file, the file specified in the FILENAME statement is used, even if the NAME= option is specified. See Summary of How Output Filenames and GRSEG Names Are Handled.
Here is an example that shows how to send the output of the GCHART procedure to file mychart.png in the MyGraphs directory.
filename graphout "MyGraphs";
goptions reset=all device=png gsfname=graphout;
ods html close;
ods listing;
proc gchart data=sashelp.cars;
   pie Make / name="MYCHART";
      where MSRP <= 15000;
   run;
quit
ods listing close;
ods html;
If a MYCHART GRSEG entry does not already exist in the temporary catalog, the device sends the output to file mychart.png in the Mygraphs directory. If a MYCHART GRSEG entry already exists, the device uses an incremented name such as MYCHART1. In the previous example, you can replace the aggregate file location with a filename in the FILENAME statement and omit the NAME= option and get the same result.
If you specify the filename in the FILENAME statement, you must include the proper file extension. See About File Extensions.
You can also store your output in a graphics output file on a remote host using FTP. Here is an example that uses FTP to store multiple PNG graphs in directory /public/sas/graphs on the remote UNIX host unixhost73.
filename grafout ftp "/public/sas/graphs" dir host="unixhost73" fileext
   user="anonymous";
ods html close;
ods listing style=banker;
goptions reset=all device=png gsfname=grafout;

/* Create our data set by sorting sashelp.cars by type */
proc sort data=sashelp.cars out=work.cars;
   by type;
run;

/* Generate the graphs */
proc gchart data=work.cars;
   vbar Make;
      title1 "30 MPG or Better";
      where MPG_Highway >= 30;
      by type;
   run;
quit;
ods listing close;
ods html;
This example creates four PNG files in directory /public/sas/graphs on host unixhost73. Since the GCHART procedure uses BY-group processing, the FILENAME statement includes the DIR option, which defines an aggregate file storage location. If you need to create only one graph, remove the DIR option and specify the absolute path to your graphics output file in your FILENAME statement.

About Filename Indexing

When duplicate names occur in graphics output filenames, SAS/GRAPH procedures use indexing systems to determine unique names for new graphics output files. (Numbers are added to the end of the filename to create new filenames). Two indexing systems are used: ODS Statistical Graphics indexing and catalog-based indexing. ODS Statistical Graphics indexing is used in all ODS Statistical Graphics output and by the procedures listed in Filename Indexing Systems Used by SAS/GRAPH Procedures. All of the other procedures use catalog-based indexing.
Filename Indexing Systems Used by SAS/GRAPH Procedures
Indexing System
How To Control Graphics Filenames
Procedure Name
Catalog-based
NAME= option in the procedure action statement
All procedures not listed below.
ODS Statistical Graphics
GAREABAR
GKPI
GTILE
Because two independent indexing systems are used by the SAS/GRAPH procedures, it is possible that graphics output files can be overwritten if the same graphics filename both for procedures that use catalog-based indexing and for procedures that use ODS Statistical Graphics indexing. To avoid this problem, make sure that you specify different names for the procedures that use ODS Statistical Graphics indexing and the procedures that use catalog-based indexing. For example, if your application uses both the GMAP procedure and the GAREABAR procedure, and you are using the NAME= option to specify output filenames, make sure you specify different filenames for each procedure.

Specifying the Catalog Name and Entry Name for Your GRSEGs

Using the Default Catalog and Entry Name

If you omit the NAME= and GOUT= options, the SAS/GRAPH software uses the default naming convention to name the GRSEG entry and stores the entry in the default WORK.GSEG catalog. The GRSEG naming convention uses up to eight characters of the default name for the procedure as the base name for the GRSEG. If the name generated by the procedure duplicates an existing GRSEG, the name is incremented such as GCHART, GCHART1, GCHART2, and so on. For details, see the description of the NAME= option for a specific procedure.
If you specify a filename for the graphics output file and omit the NAME= option, the graphics output filename is the name specified in the FILENAME statement, and the GRSEG entry name is the default procedure name. When you specify the filename, make sure that you include the appropriate file extension, such as .cgm, .gif, or .ps.
If you specify an aggregate file storage location instead of a specific filename and you omit the NAME= option, the name of both the GRSEG entry and the graphics output file is the default procedure name, and SAS/GRAPH supplies the appropriate file extension.

Specifying a Name for Your GRSEG with the NAME= Option

You can use the NAME= option to change the name of your output. Here is an example that shows how to change the name of the GCHART procedure output to MYCHART.
filename outfile "./";
goptions reset=all device=png gsfname=outfile;
ods html close;
ods listing;
proc gchart data=sashelp.cars;
   pie Make / name="MYCHART";
      where MSRP <= 15000;
   run;
quit;
ods listing close;
ods html;
This example creates the file mychart.png in the SAS default output directory, and it creates the GRSEG Mychart in the SAS temporary catalog.
See Summary of How Output Filenames and GRSEG Names Are Handled for additional information about output naming.

Specifying the Catalog and GRSEG Name with the GOUT= and NAME= Options

By default, GRSEGs are stored in the WORK.GSEG temporary catalog under the default name of the procedure that was used to generate the graph. The GRSEG name can be specified using the NAME= option, and the output catalog can be changed using the GOUT= procedure option. GRSEG names are limited to eight characters. If the NAME= option is set to a name that is more than eight characters in length, the GRSEG name is truncated to eight characters.
The name of the library and catalog in which the GRSEG is stored can be changed with the GOUT= procedure option. The GOUT= procedure option is assigned the catalog name in the format libref.catalog for the desired catalog. The name can be a one-level or a two-level name. If a one-level name is used, the GRSEG is stored in the temporary WORK library under the specified catalog name. A two-level name can be used to specify a permanent catalog.
Here is an example that shows how to store a GRSEG generated by the GCHART procedure under entry MYCHART in the MYGRAPHS.CARS catalog.
LIBNAME Mygraphs "Mygraphs";
ods html close;
ods listing style=banker;

proc gchart data=sashelp.cars gout=Mygraphs.cars;
   vbar Make / name="Mychart";
      where MPG_Highway >= 37;
   run;
quit;
ods listing close;
ods html;
How NAME= and GOUT= Affect the GRSEG Location summarizes the location of the GRSEG based on the NAME= and GOUT= procedure using the GCHART procedure as an example.
How NAME= and GOUT= Affect the GRSEG Location
NAME=
GOUT=
GRSEG Location
Not specified
Not specified
Gchart in WORK.GSEG
Not specified
CARS
Gchart in WORK.CARS
Not specified
MYGRAPHS.CARS
Gchart in MYGRAPHS.CARS
MYCHART
Not specified
Mychart in WORK.GSEG
MYCHART
CARS
Mychart in WORK.CARS
MYCHART
MYGRAPHS.CARS
Mychart in MYGRAPHS.CARS

Where GRSEGs Are Stored When Multiple ODS Destinations Are Used

When you send output to multiple ODS destinations, a catalog is created for the GRSEGs for each of the destinations. If the GOUT= procedure option is not specified, by default, the GRSEGs for the first destination that was opened are sent to the WORK.GSEG catalog. The GRSEGs for the subsequently opened ODS destinations are sent to a catalog that is named after the destination itself. For example, if you open the ODS LISTING, HTML, and RTF destinations, in that order, the GRSEGs are stored in the catalogs that are shown in the following table.
Catalog Names for Default Catalog and Multiple ODS Destinations
Catalog Name
Content
WORK.GSEG
The GRSEGs for ODS LISTING
WORK.HTML
The GRSEGs for ODS HTML
WORK.RTF
The GRSEGs for ODS RTF
In the default case, the GRSEGs for the first destination that is opened are stored in the WORK.GSEG catalog, regardless of the destination.
If you use the GOUT= procedure option to specify a catalog name, the GRSEGs for the first destination that you opened are sent to the catalog that is specified by the GOUT= procedure option. The GRSEGs for the subsequently opened ODS destinations are sent to a catalog that is named after the destination itself. For example, if you open the ODS HTML, LISTING, and RTF destinations, and you use the GOUT=MyGraphs.Sales procedure option, the GRSEGs are stored in the catalogs that are shown in the following table.
Catalog Names for User-Specified Catalog and Multiple ODS Destinations
Catalog Name
Content
MYGRAPHS.SALES
The GRSEGs for ODS HTML
MYGRAPHS.LISTING
The GRSEGs for ODS LISTING
MYGRAPHS.RTF
The GRSEGs for ODS RTF
The GRSEGs for the first destination are stored in the catalog that is specified by the GOUT= procedure option.

Summary of How Output Filenames and GRSEG Names Are Handled

How SAS/GRAPH Generates Initial GRSEG Names and Filenames summarizes how SAS/GRAPH generates names for catalog entries and graphics output files, depending on 1) whether the NAME= option is used, and 2) the file reference specification in the FILENAME statement. This illustration assumes that the GCHART procedure is used with the DEVICE=GIF graphics option. It describes the case where a GRSEG and output file of the same name do not already exist, and the case where they do already exist.
How SAS/GRAPH Generates Initial GRSEG Names and Filenames
NAME=
Condition
Result
NAME="FRED"
GSFNAME= points to a file named "MYGRAPH.GIF" and the catalog is empty.
GRSEG name: FRED
external filename: MYGRAPH.GIF
NAME="FRED"
GSFNAME= points to an aggregate file storage location and the catalog is empty.
GRSEG name: FRED
external filename: FRED.GIF
NAME="MYIMAGES"
The NAME= value is exactly eight characters in length. GSFNAME= points to an aggregate file storage location and the catalog is empty.
GRSEG name:MYIMAGES
external filename:MYIMAGES.GIF
NAME="WEATHEROBS"
GSFNAME= points to an aggregate file storage location and the catalog is empty.
GRSEG name:WEATHERO
external filename: WEATHEROBS.GIF
NAME= (not specified)
GSFNAME= points to a file named "MYGRAPH.GIF" and the catalog is empty.
GRSEG name: GCHART
external filename: MYGRAPH.GIF
NAME= (not specified)
GSFNAME= points to an aggregate file storage location and the catalog is empty.
GRSEG name: GCHART
external filename: GCHART.GIF
Note: When the file reference points to an aggregate file storage location, the name of the GRSEG always determines the name of the graphics output file. It does not matter whether the GRSEG name is the default name or a name assigned by the NAME= option.
CAUTION:
If the graph created by your program already exists in the catalog, a new GRSEG with an incremented name is created. A new graphics output file might be created, which leaves your old graphics output file in place.
Although GRSEG names cannot be more than eight characters in length, the NAME= option supports long names. When the NAME= option is assigned a name of more than eight characters and the file reference points to an aggregate file location, the GRSEG name is the NAME= value truncated to eight characters, and the graphics output filename is the complete NAME= value. This is demonstrated by the NAME="WEATHEROBS" example in How SAS/GRAPH Generates Initial GRSEG Names and Filenames.
When a GRSEG of the same name already exists in the catalog, the SAS/GRAPH software combines the NAME= option value with a number to create an incremented name of no more than eight characters. If the GSFNAME= graphics option is used and the file reference points to an aggregate file location, the new graphics output filename is also incremented using the same number that is used for the GRSEG name. The way in which the incremented graphics output filename is formed depends on the length of the NAME= value as follows:
  • If the length of the NAME= value is less than eight characters or more than eight characters, the number that is used in the GRSEG name is appended to the NAME= value.
  • If the length of the NAME= value is exactly eight characters, the number that is used in the GRSEG name is appended to the first seven characters of the NAME= value.
If the GSFNAME= graphics option points to a file, the graphics output filename remains the same and the original file is replaced with the new graph by default.
How SAS/GRAPH Increments GRSEG Names and Filenames demonstrates how the SAS/GRAPH software increments the GRSEG name and the graphics output filenames when a GRSEG and graphics output file of the same name already exist.
How SAS/GRAPH Increments GRSEG Names and Filenames
NAME=
Condition
Result
NAME="FRED"
GSFNAME= points to a file named "MYGRAPH.GIF" and GRSEG FRED already exists.
GRSEG name: FRED1
external filename: MYGRAPH.GIF
NAME="FRED"
GSFNAME= points to an aggregate file storage location and GRSEG FRED already exists.
GRSEG name: FRED1
external filename: FRED1.GIF
NAME="MYIMAGES"
The NAME= value is exactly eight characters in length. GSFNAME= points to an aggregate file storage location and GRSEG MYIMAGES already exists.
GRSEG name:MYIMAGE1
external filename:MYIMAGE1.GIF
NAME="WEATHEROBS"
GSFNAME= points to an aggregate file storage location and GRSEG WEATHERO already exists.
GRSEG name:WEATHER1
external filename: WEATHEROBS1.GIF
NAME= (not specified)
GSFNAME= points to a file named "MYGRAPH.GIF" and GRSEG GCHART already exists.
GRSEG name: GCHART1
external filename: MYGRAPH.GIF
NAME= (not specified)
GSFNAME= points to an aggregate file storage location and GRSEGs GCHART and GCHART1 already exist.
GRSEG name: GCHART2
external filename: GCHART2.GIF
Notice that in the NAME="MYIMAGES" example the incremented external filename is formed by appending the number to the first seven characters of the NAME= value, while in the NAME="WEATHEROBS" and NAME="FRED" examples, the incremented external filename is formed by appending the number to the full NAME= value. Be aware that the way in which the incremented graphics output filename is formed is different when the length of the NAME= value is exactly eight characters than when it is more or less than eight characters.
You cannot replace individual GRSEGs in a catalog. To replace a GRSEG, you must delete the GRSEG, and then re-create it. Therefore, even though the contents of the graphics output file are replaced, the GRSEG is not. Each time you submit the program, a new GRSEG is created, and the GRSEG name is incremented.