| SAS Companion for the Microsoft Windows Environment |
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 discussed in Opening and Saving Files. The method you use to access external files
depends on the needs of your SAS application and your personal preference.
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 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 file named 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 gives you the option of replacing the
existing file, appending the contents of the window to the existing file,
or canceling your request.
If you issue the FILE command with no arguments, the
contents of the window are written to the file referenced in the last FILE
command. This 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 you issue the plain FILE command. Thereafter, unless you
specify the filename in the FILE command, it uses the parameters you specified
earlier (replace or append) without prompting you.
Choosing Save As from the
SAS AWS 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 Opening and Saving Files.
The FILE command also accepts several options. These
options enable you, among other things, to associate a device with the output
file and 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.
The INCLUDE command, like the %INCLUDE statement, can
be used to copy an entire external file into the PROGRAM 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 PROGRAM 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, assuming the PROGRAM EDITOR is the active window, to copy
the member PROG1 into the PROGRAM 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 options, such as invoking the program you are copying. The
Open dialog box is the most flexible way for you to copy files into the PROGRAM
EDITOR window. For more information, see Opening and Saving Files.
The INCLUDE command also accepts several options. These
options enable you, among other things, to associate a device with the input
file and 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 INCLUDE command, see INCLUDE.
Issuing the INCLUDE command with no
arguments includes
the file referenced in the last INCLUDE command. If no previous INCLUDE command
exists, you receive an error message.
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 SAS Language Reference: Dictionary.
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.