Copying, Moving, and Deleting SAS Data Sets |
Moving Libraries |
The COPY statement provides the MOVE option to move SAS data sets from the input library (either the procedure input library or the input library named with the IN= option) to the output library (named with the OUT= option). Note that with the MOVE option, SAS first copies the files to the output library, then deletes them from the input library.
The following statements move all the data sets in the library PRECIP to the library CLIMATE:
copy out=climate move; run;
The following SAS log shows that the data sets in PRECIP were moved to CLIMATE:
Moving Data Sets in the Library PRECIP to the Library CLIMATE
116 copy out=climate move; 117 run; NOTE: Moving PRECIP.RAIN to CLIMATE.RAIN (memtype=DATA). NOTE: There were 5 observations read from the data set PRECIP.RAIN. NOTE: The data set CLIMATE.RAIN has 5 observations and 4 variables. NOTE: Moving PRECIP.SNOW to CLIMATE.SNOW (memtype=DATA). NOTE: There were 3 observations read from the data set PRECIP.SNOW. NOTE: The data set CLIMATE.SNOW has 3 observations and 4 variables.
After moving files with the MOVE option, a directory listing of PRECIP from the CONTENTS statement confirms that there are no members in the library. As the output from the following statements illustrates, the library PRECIP no longer contains any data sets; therefore, the library CLIMATE contains the only copy of the data sets RAIN and SNOW.
contents data=_all_ nods; run;
The following outputs show the SAS log, then the directory listing for the library PRECIP:
SAS Log from the CONTENTS Statement
135 contents data=_all_ nods; 136 run; WARNING: No matching members in directory.
Directory Listing of the Library PRECIP Showing No Data Sets
The SAS System The DATASETS Procedure -----Directory----- Libref: PRECIP Engine: V8 Physical Name: external-file File Name: external-file Inode Number: 1864994 Access Permission: rwxr-xr-x Owner Name: userid File Size (bytes): 4096
Note: The data sets are deleted from the SAS data library PRECIP, but the libref is still assigned. The name that is assigned to the library in your operating environment is not removed when you move all files from one library to another.
Moving Specific Data Sets |
You can use the SELECT and EXCLUDE statements to move one or more SAS data sets. For example, the following statements move the data set HURRICANE from the library USCLIM to the library STORM:
copy in=usclim out=storm move; select hurricane; run;
Moving the Data Set HURRICANE from the Library USCLIM to the Library STORM
173 copy in=usclim out=storm move; 174 select hurricane; 175 run; NOTE: Moving USCLIM.HURRICANE to STORM.HURRICANE (memtype=DATA). NOTE: There were 5 observations read from the data set USCLIM.HURRICANE. NOTE: The data set STORM.HURRICANE has 5 observations and 5 variables.
Similarly, the following code uses the EXCLUDE statement to move all files except the data set SNOW from the library CLIMATE to the library USCLIM:
copy in=climate out=usclim move; exclude snow; run;
Moving All Data Sets Except SNOW from the Library CLIMATE to the Library USCLIM
193 copy in=climate out=usclim move; 194 exclude snow; 195 run; NOTE: Moving CLIMATE.HIGHTEMP to USCLIM.HIGHTEMP (memtype=DATA). NOTE: There were 5 observations read from the data set CLIMATE.HIGHTEMP. NOTE: The data set USCLIM.HIGHTEMP has 5 observations and 4 variables. NOTE: Moving CLIMATE.LOWTEMP to USCLIM.LOWTEMP (memtype=DATA). NOTE: There were 5 observations read from the data set CLIMATE.LOWTEMP. NOTE: The data set USCLIM.LOWTEMP has 5 observations and 4 variables. NOTE: Moving CLIMATE.RAIN to USCLIM.RAIN (memtype=DATA). NOTE: There were 5 observations read from the data set CLIMATE.RAIN.
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.