Brings a SAS programming statement, data lines, or both, into
a current SAS program
| Valid: |
anywhere
|
| Category: |
Program Control
|
| Alias: |
%INC
|
%INCLUDE source(s)
</<SOURCE2>
<S2=length> <host-options>>;
|
-
source
-
describes the location of the information
that you want to access with the %INCLUDE statement. There are three possible
sources:
-
file-specification
-
identifies an entire external file that
you want to bring into your program.
Operating Environment Information:
For
complete details
on specifying the physical names of external files, see the SAS documentation
for your operating environment.
File-specification can have these forms:
-
'external-file'
-
specifies the physical name of an external
file that is enclosed in quotation marks. The physical name is the name by
which the operating environment recognizes the file.
-
fileref
-
specifies a fileref that has previously
been associated with an external file.
-
fileref(filename-1 <,
"filename-2.xxx",
... filename-n>)
-
specifies a fileref that has previously
been associated with an aggregate storage location. Follow the fileref with
one or more filenames that reside in that location. Enclose the filenames
in one set of parentheses, and separate each filename with a comma, space.
This example instructs SAS to include the files "testcode1.sas",
"testcode2.sas"
and "testcode3.txt." These files are located in aggregate storage
location "mycode." You do not need to specify the file extension
for testcode1 and testcode2 because they are the default .SAS extension. You
must enclose testcode3.txt in quotation marks with the whole filename specified
because it has an extension other than .SAS:
%include mylib(testcode1, testcode2,
"testcode3.txt");
Operating Environment Information:
Different
operating
environments call an aggregate grouping of files by different names, such
as a directory, a MACLIB, a text library, or a partitioned data set. For complete
details on specifying external files, see the SAS documentation for your operating
environment.
Operating Environment Information:
The character
length
that is allowed for filenames is operating environment specific. For information
on accessing files from a storage location that contains several files, see
the SAS documentation for your operating environment.
-
internal-lines
-
includes lines that are entered earlier
in the same SAS job or session.
To include internal lines, use any of the following:
Note:
The SPOOL system option controls internal access
to previously submitted lines when you run SAS in interactive line mode, noninteractive
mode, and batch mode. Use the OPTIONS procedure to determine the current setting
of the SPOOL system option on your system. ![[cautend]](../common/images/cautend.gif)
-
keyboard-entry
-
is a method for preparing a program so that
you can interrupt the current program's execution, enter statements or data
lines from the keyboard, and then resume program processing.
Note:
The fileref SASTERM must have been previously
associated with an external file in a FILENAME statement or function or an
operating environment command. ![[cautend]](../common/images/cautend.gif)
-
SOURCE2
-
causes the SAS log to show the source statements
that are being included in your SAS program.
-
S2=length
-
specifies the length of the record to be
used for input. Length can have these values:
-
host-options
-
Operating Environment Information:
Operating
environments can support various options for the %INCLUDE statement. See the
documentation for your operating environment for a list of these options and
their functions. ![[cautend]](../common/images/cautend.gif)
When you execute a program that contains the %INCLUDE
statement, SAS executes your code, including any statements or data lines
that you bring into the program with %INCLUDE.
Operating Environment Information:
Use of the
%INCLUDE statement is dependent on your operating environment.
See the documentation for your operating environment for more information
about additional software features and methods of referring to and accessing
your files. See your documentation before you run the examples for this statement.
The %INCLUDE statement accesses
SAS statements and data lines
from three possible sources:
The %INCLUDE statement is most often used when running
SAS in interactive line mode, noninteractive mode, or batch mode. Although
you can use the %INCLUDE statement when you run SAS using windows, it may
be more practical to use the INCLUDE and RECALL commands to access data lines
and program statements, and submit these lines again.
The %INCLUDE statement executes
statements immediately.
The INCLUDE command brings the included lines into the PROGRAM EDITOR window
but does not execute them. You must issue the SUBMIT command to execute those
lines.
-
This example stores a portion of a program in
a file and includes it in a program to be written later. This program is stored
in a file named MYFILE:
data monthly;
input x y month $;
datalines;
1 1 January
2 2 February
3 3 March
4 4 April
;
This program includes an external file named MYFILE
and submits the DATA step that it contains before the PROC PRINT step executes:
%include 'MYFILE';
proc print;
run;
-
To reference a file by using a fileref rather
than the actual file name, you can use the FILENAME statement (or a command
recognized by your operating environment) to assign a fileref:
filename in1 'MYFILE';
You can later access MYFILE with the fileref IN1:
%inc in1;
-
If you want to use many files that are stored
in a directory, PDS, or MACLIB (or whatever your operating environment calls
an aggregate storage location), you can assign the fileref to the larger storage
unit and then specify the filename. For example, this FILENAME statement assigns
the fileref STORAGE to an aggregate storage location:
filename storage
'aggregate-storage-location';
You can later include a file using this statement:
%inc storage(MYFILE);
-
You can also access several files or members from
this storage location by listing them in parentheses after the fileref in
a single %INCLUDE statement. Separate filenames with a comma or a blank space.
The following %INCLUDE statement demonstrates this method:
%inc storage(file-1,file-2,file-3);
When the file does not have the default .SAS extension,
you can access it using quotation marks around the complete filename listed
inside the parentheses.
-
%inc storage("file-1.txt","file-2.dat",
"file-3.cat");
This %INCLUDE statement causes SAS to process lines 1, 5, 9
through 12, and 13 through 16 as though you had entered them again from your
keyboard:
%include 1 5 9-12 13:16;
- CAUTION:
- The method shown in this example is valid only when you run SAS
in noninteractive mode or interactive line mode.
![[cautend]](../common/images/cautend.gif)
This example uses %INCLUDE to add a customized TITLE
statement when PROC PRINT executes:
data report;
infile file-specification;
input month $ salesamt $;
run;
proc print;
%include *;
run;
When this DATA step executes, %INCLUDE with the asterisk
causes SAS to issue a prompt for statements that are entered at the terminal.
You can enter statements such as
where month= 'January';
title 'Data for month of January';
After you enter statements, you can use %RUN to resume
processing by typing
%run;
The %RUN statement signals to SAS to leave keyboard-entry
mode and resume reading and executing the remaining SAS statements from the
original program.
This example submits the source code from three entries in the
catalog MYLIB.INCLUDE. When no entry type is specified, the default is CATAMS.
filename dir catalog 'mylib.include';
%include dir(mem1);
%include dir(mem2);
%include dir(mem3);
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.