PROC DATASETS - COPY, MOVE, SELECT & EXCLUDE Statements

Setting up the Background

SAS Code:

libname xyz 'D:\SAS_Datasets\';

data xyz.a;

amt = 5600;

run;

data xyz.b;

run;

data xyz.c;

amt = 5600;

run;

data xyz.d;

amt = 5600;

run;

proc datasets;

COPY IN= source_library_name OUT = target_library_name MOVE;

SELECT/EXCLUDE list_of_datasets_to_be_processed;

quit;

EXAMPLE:

Before moving to the actual demonstrations we will setup the environment.

Following code declares one library and creates some SAS datasets inside; just for demo purpose.

/* For Moving dataset across the libraries */

proc datasets;

COPY IN= source_library_name OUT = target_library_name;

SELECT/EXCLUDE list_of_datasets_to_be_processed;

quit;

SYNTAX:

/* For Copying dataset into another library */

Along with this basic functionalities we are also going to learn SELECT and EXCLUDE statements with PROC DATASETS.

SELECT statement will select only the mentioned datasets for further processing

EXCLUDE statement will select all the datasets except those listed in EXCLUDE statement for further processing.

SELECT and EXCLUDE statements can be used interchangably. Provision of these statements has been made just to reducing the typing efforts of the programmer. (Nice to see that some one cares so much about the pitty programmer !!!)

The basic difference between Copying and Moving datasets is that; By using COPY we will end up having 2 copies of those datasets one at new location and one original copy at original location.

While MOVE statement will move the dataset to new location and the dataset at original location will get erased.

<< Back to the PROC DATASETS Page.

In this section we are going to learn following concepts

A] How to copy datasets from one location to another

B] How to move the dataset between two locations

amt = 5600;

In addition to creating the XYZ library; for demonstrating the above steps we are going to create another temporary library 'TEMP' on the disk.

SAS Code: PROC DATASETS COPY, MOVE, SAVE & EXCLUDE Statements

libname xyz 'D:\SAS_Datasets\';

libname temp 'D:\SAS_Datasets\Temp';

/* This code will create a separate copy of dataset C under temp library */

proc datasets;

copy in=xyz out=temp ;

select c;

quit;

/* This code will move the all the datasets (except a, b and c i.e. only D) from library xyz to temp */

proc datasets;

copy in=xyz out=temp move;

exclude a b c;

quit;

proc datasets lib=xyz;

quit;

proc datasets lib=temp;

quit;

Make a note of MOVE option used along with COPY statement in second PROC DATASETS code which is trying to dataset D from library XYZ to TEMP. Lets see the output of the code above.

OUTPUT: PROC DATASETS COPY, MOVE, SAVE & EXCLUDE Statements

If we observe the output more closely; Dataset C has been copied into library TEMP so it has got two copies in each of the library. However in second case dataset D has been literally moved from XYZ library to TEMP library and hence it has only one copy in TEMP library.

PROC DATASETS>> CONETNTS MODIFY/RENAME/FORMAT APPEND COPY/MOVE DELETE KILL