Previous Page | Next Page

Using External Files under Windows

Accessing External Files with SAS Commands

This section illustrates how to use the FILE and INCLUDE commands to access external files. Commands provide the same service as the Save As and Open dialog boxes. The method that you use to access external files depends on the needs of your SAS application and your personal preference.


Using the FILE Command

The FILE command has a different use than the FILE statement; the FILE command writes the current contents of a window to an external file rather than merely specifying, for example, a destination for PUT statement output in a DATA step.

For example, if you want to save the contents of the LOG window to an external filename C:\SASLOGS\TODAY.LOG, you can issue the following FILE command from the Command dialog box; however, the LOG window must be active:

file "c:\saslogs\today.log"

If you have already defined the fileref LOGS to point to the SASLOGS directory, you can use the following FILE command:

file logs(today)

In this case, the file extension defaults to .log, as shown in Default File Extensions for Referencing External Files with Member-Name Syntax.

If you use the FILE command to attempt to write to an already existing file, a dialog box enables you to replace the existing file, append the contents of the window to the existing file, or cancel your request.

If you issue the FILE command with no arguments, the contents of the window are written to the file that is referenced in the last FILE command. This action is useful if you are editing a program and want to save it often. However, the dialog box that prompts you about replacing or appending appears only the first time that you issue the FILE command. Thereafter, unless you specify the filename in the FILE command, it uses the parameters that you specified earlier (replace or append) without prompting you.

Choosing Save As from the SAS main window File menu displays the Save As dialog box. This dialog box performs the same function as the FILE command, but it is more flexible in that it gives you more choices and is more interactive than the FILE command. For more information, see "Saving Files" in Saving Files and Using the Program Editor.

The FILE command also accepts several options. These options enable you to control the record format and length. Some of these options are illustrated in Advanced External I/O Techniques. For the complete syntax of the FILE command, see FILE Command: Windows.


Using the INCLUDE Command

The INCLUDE command, like the %INCLUDE statement, can be used to copy an entire external file into the Editor window, the NOTEPAD window, or whatever window is active. In the case of the INCLUDE command, however, the file is simply copied to the window and is not submitted.

For example, suppose you want to copy the file C:\SAS\PROG1.SAS into the Editor window. If you have defined a fileref SAMPLE to point to the correct directory, you can use the following INCLUDE command from the Command dialog box (if the Editor is the active window) to copy the member PROG1 into the Editor window:

include sample(prog1);

Another way to copy files into your SAS session is to use the Open dialog box. In addition to copying files, the Open dialog box gives you other choices, such as invoking the program that you are copying. The Open dialog box is the most flexible way for you to copy files into the Editor window. For more information, see "Opening Files" in Using the Enhanced Editor and Using the Program Editor.

The INCLUDE command also accepts several arguments. These arguments enable you to control the record format and length. Some of these arguments are illustrated in Advanced External I/O Techniques. For the complete syntax of the INCLUDE command, see INCLUDE Command: Windows.

Issuing the INCLUDE command with no arguments includes the that is file referenced in the last INCLUDE command. If no previous INCLUDE command exists, you receive an error message.


Using the GSUBMIT Command

The GSUBMIT command can be used to submit SAS statements that are stored in the Windows clipboard. To submit SAS statements from the clipboard, use the following command:

gsubmit buffer=default;

You can also use the GSUBMIT command to submit SAS statements that are specified as part of the command. For more information about the GSUBMIT command, see the SAS Help and Documentation.

Note:   SAS statements in the Windows clipboard will not be submitted using the GSUBMIT command if a procedure that you submitted using the Enhanced Editor is still running.

You can copy the SAS statements to a new Enhanced Editor window and then submit them.  [cautionend]

Previous Page | Next Page | Top of Page