Statements |
Valid: | anywhere |
Category: | Program Control |
Alias: | %INC |
See: | %INCLUDE Statement under Windows UNIX OpenVMS z/OS |
Syntax |
%INCLUDE source(s)
</<SOURCE2> <S2=length> <operating-environment-options>>; |
describes the location of the information that you want to access with the %INCLUDE statement. There are three possible sources:
identifies an entire external file that you want to bring into your program.
Operating Environment Information: The character length allowed for filenames is operating environment specific. 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:
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.
specifies a fileref that has previously been associated with an external file.
Tip: | You can use a FILENAME statement or function or an operating environment command to make the association. |
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 "mylib." 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");
Note: A file that is located in an aggregate storage location and has a name that is not a valid SAS name must have its name enclosed in quotation marks.
Tip: | You can use a FILENAME statement or function or an operating environment command to make the association. |
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 information about accessing files from a storage location that contains several files, see the SAS documentation for your operating environment.
Tip: | You can verify the existence of file-specification by using the SYSERR macro variable if the ERRORCHECK option is set to STRICT. |
includes lines that are entered earlier in the same SAS job or session.
To include internal lines, use any of the following:
n | |
n-m or n:m |
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. By default, the SPOOL system option is set to NOSPOOL. The SPOOL system option must be in effect in order to use %INCLUDE statements with internal line references. Use the OPTIONS procedure to determine the current setting of the SPOOL system option on your system.
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.
causes the SAS log to show the source statements that are being included in your SAS program.
specifies the length of the record to be used for input. Length can have these values:
Tip: |
Text input from the %INCLUDE
statement can be either fixed or variable length.
|
Interaction: | The S2= system option also specifies the length of secondary source statements that are accessed by the %INCLUDE statement, and it is effective for the duration of your SAS session. The S2= option in the %INCLUDE statement affects only the current include operation. If you use the option in the %INCLUDE statement, it overrides the system option setting for the duration of the include operation. |
See Also: | For a detailed discussion of fixed- and variable-length input records, see S= System Option and S2= System Option. |
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.
Details |
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 might be more practical to use the INCLUDE and RECALL commands to access data lines and program statements, and submit these lines again.
You can specify any number of sources in a %INCLUDE statement, and you can mix the types of included sources. Note, however, that although it is possible to include information from multiple sources in one %INCLUDE statement, it might be easier to understand a program that uses separately coded %INCLUDE statements for each source.
The %INCLUDE statement must begin at a statement boundary. That is, it must be the first statement in a SAS job or must immediately follow a semicolon ending another statement. A %INCLUDE statement cannot immediately follow a DATALINES, DATALINES4, CARDS, or CARDS4 statement (or PARMCARDS or PARMCARDS4 statement in procedures that use those statements). However, you can include data lines with the %INCLUDE statement using one of these methods:
The %INCLUDE statement can be nested within a file that has been accessed with %INCLUDE. The maximum number of nested %INCLUDE statements that you can use depends on system-specific limitations of your operating environment (such as available memory or the number of files you can have open concurrently).Because %INCLUDE is a global statement and global statements are not executable, the %INCLUDE statement cannot be used in conditional logic.
The maximum line length is 32K bytes.
Comparisons |
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.
Examples |
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 filename, 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 if you had entered them again from your keyboard:
%include 1 5 9-12 13:16;
The method shown in this example is valid only when you run SAS in noninteractive mode or interactive line mode.
Restriction: | The asterisk (*) cannot be used to specify keyboard entry if you use the Enhanced Editor in the Microsoft Windows operating environment. |
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 keyboard. 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);
See Also |
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.