Language Reference


CLOSE Statement

  • CLOSE <SAS-data-set>;

  • CLOSE (matrix);

The CLOSE statement is used to close one or more SAS data sets opened with the USE , EDIT , or CREATE statement.

The optional argument specifies the name of one or more SAS data sets. The data sets can be specified with a literal value or with an expression that resolves to the name of a SAS data set. You can specify a one-level name (for example, A) or a two-level name (for example, Sasuser.A). For example, the following statements are valid:

use Sashelp.Class;
close Sashelp.Class;/* literal value */
f = "Sashelp.Class";
use (f);
close (f);          /* expression */

If you do not specify a data set name, the current data set is closed. For more information about specifying SAS data sets, refer to ChapterĀ 7: Working with SAS Data Sets.

You can use the SHOW DATASETS statement to find the names of open data sets.

SAS/IML software automatically closes all open data sets when a QUIT statement is executed.

The following statements provide examples of using the CLOSE statement:

use Sashelp.Class;
read all var _NUM_ into x[colname=VarName];

corr = corr(x);
create ClassCorr from corr[rowname=VarName colname=VarName];
append from corr[rowname=VarName];

show datasets;
close Sashelp.Class ClassCorr;

Figure 24.70: Open Data Sets

LIBNAME  MEMNAME                          OPEN MODE   STATUS                    
-------- -------------------------------- ---------   --------                  
SASHELP  CLASS                            Input                                 
WORK     CLASSCORR                        Update      Current Input/Output      
                                                                                



It is good programming practice to close data sets when you are finished using them.