Note: You cannot use the DATASETS procedure to change the values of observations,
to create or delete variables, or to change the type or length of variables. These
modifications are done with DATA step statements and functions.
Prerequisites
Before using this section, you should understand the concepts presented in the following
sections:
Chapter 35, “Understanding SAS Libraries,” on page 687
Chapter 36, “Managing SAS Libraries,” on page 695
Chapter 37, “Getting Information about Your SAS Data Sets,” on page 701
Input Data Library for Examples
The examples in this section use a SAS library that contains information about the
climate of the United States. The DATA steps that create the data sets in the SAS library
are shown in “The CLIMATE, PRECIP, and STORM Data Sets” on page 820.
Renaming SAS Data Sets
Renaming data sets is often required for effective library management. For example, you
might rename a data set when you archive it or when you add new data values.
Use the CHANGE statement in the DATASETS procedure to rename one or more data
sets in the same library. Here is the syntax for the CHANGE statement:
CHANGE old-name=new-name;
old-name
specifies the current name of the SAS data set.
new-name
specifies the name that you want to give the data set.
This example renames two data sets in the SAS library USCLIM, which contains
information about the climate of the United States. The following program starts the
DATASETS procedure. It then changes the name of the data set HIGHTEMP to
USHIGH and the name of the data set LOWTEMP to USLOW:
libname usclim 'SAS-library';
proc datasets library=usclim;
change hightemp=ushigh lowtemp=uslow;
run;
714 Chapter 38 Modifying SAS Data Set Names and Variable Attributes
As it processes these statements, SAS sends messages to the SAS log. The messages
verify that the data sets are renamed:
Log 38.1 Renaming Data Sets in the Library USCLIM
38 proc datasets library=usclim;
39 change hightemp=ushigh lowtemp=uslow;
40 run;
NOTE: Changing the name USCLIM.HIGHTEMP to USCLIM.USHIGH (memtype=DATA).
NOTE: Changing the name USCLIM.LOWTEMP to USCLIM.USLOW (memtype=DATA).
The following program executes the DATASETS procedure, where you can see the
results of the changes:
proc datasets library=usclim;
run;
The following output shows information about the library:
Figure 38.1 Renaming Data Sets in the Library USCLIM
Renaming SAS Data Sets 715

Get Step-by-Step Programming with Base SAS 9.4, Second Edition, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.