CLOSEFILE Statement

CLOSEFILE files ;

The CLOSEFILE statement is used to close files opened by the INFILE or FILE statement.

The statement arguments specify the name of one or more file specifications. You can specify names (for defined filenames), literals, or expressions in parentheses (for pathnames). Each file specification should be the same as when the file was opened.

To find out what files are open, use the SHOW FILES statement. For further information, see Chapter 8. See also the description of the SAVE statement.

SAS/IML software automatically closes all files when a QUIT statement is executed.

The following example opens and closes an external file named MyData.txt that resides in the current directory. (If you run PROC IML through a SAS Display Manager Session (DMS), you can change the current directory by selecting Tools Options Change Current Folder from the main menu.)

filename MyFile 'MyData.txt';
infile MyFile;
show files;
closefile MyFile;

Figure 23.62 Open External File
FILE NAME                   MODE            EOF    OPTIONS                      
---------                  ------          -----   --------                     
FILENAME:MYFILE            Current Input , no eof, lrecl=512 STOPOVER           
                                                                                

Alternatively, you can specify the full path of the file, as shown in the following statements:

src = "C:\My Data\MyData.txt";
infile (src);
show files;
closefile (src);

Figure 23.63 Open File Specified by a Full Path
FILE NAME                   MODE            EOF    OPTIONS                      
---------                  ------          -----   --------                     
C:\My Data\MyData.txt      Current Input , no eof, lrecl=512 STOPOVER