Previous Page | Next Page

SAS Data Sets

Data Set Names


Where to Use Data Set Names

You can use SAS data sets as input for DATA or PROC steps by specifying the name of the data set in the following:


How and When SAS Data Set Names Are Assigned

You name SAS data sets when you create them. Output data sets that you create in a DATA step are named in the DATA statement. SAS data sets that you create in a procedure step are usually given a name in the procedure statement or an OUTPUT statement. If you do not specify a name for an output data set, SAS assigns a default name.

If you are creating SAS views, you assign the data set name using one of the following:

Note:   Because you can specify both SAS data files and SAS views in the same program statements but cannot specify the member type, SAS cannot determine from the program statement which one you want to process. This is why SAS prevents you from giving the same name to SAS views and SAS data sets in the same library.  [cautionend]


Parts of a Data Set Name

The complete name of every SAS data set has three elements. You assign the first two; SAS supplies the third. The form for SAS data set names is as follows:

libref.SAS-data-set.membertype

The elements of a SAS data set name include the following:

libref

is the logical name that is associated with the physical location of the SAS library.

SAS-data-set

is the data set name, which can be up to 32 bytes long for the Base SAS engine starting in Version 7. Earlier SAS versions are limited to 8-byte names.

membertype

is assigned by SAS. The member type is DATA for SAS data files and VIEW for SAS views.

When you refer to SAS data sets in your program statements, use a one- or two-level name. You can use a one-level name when the data set is in the temporary library WORK. In addition, if the reserved libref USER is assigned, you can use a one-level name when the data set is in the permanent library USER. Use a two-level name when the data set is in some other permanent library you have established. A two-level name consists of both the libref and the data set name. A one-level name consists of just the data set name.


Two-level SAS Data Set Names

The form most commonly used to create, read, or write to SAS data sets in permanent SAS libraries is the two-level name as shown here:

libref.SAS-data-set

When you create a new SAS data set, the libref indicates where it is to be stored. When you reference an existing data set, the libref tells SAS where to find it. The following examples show the use of two-level names in SAS statements:

data revenue.sales;

proc sort data=revenue.sales;


One-level SAS Data Set Names

You can omit the libref, and refer to data sets with a one-level name in the following form:

SAS-data-set

Data sets with one-level names are automatically assigned to one of two SAS libraries: WORK or USER. Most commonly, they are assigned to the temporary library WORK and are deleted at the end of a SAS job or session. If you have associated the libref USER with a SAS library or used the USER= system option to set the USER library, data sets with one-level names are stored in that library. See SAS Libraries for more information on using the USER and WORK libraries. The following examples show how one-level names are used in SAS statements.

/* create perm data set in location of USER=option*/
options user='c:\temp'
data test3;         

/* create perm data set in current directory */data 'test3';      

/* create a temp data set in WORK directory if USER= is not specified*/
data stratifiedsample1;

Previous Page | Next Page | Top of Page