Return to Archive

SAS Tip of the Month
October 2008

Making a copy of a SAS dataset is a basic operation in SAS. This is usually done when we want to bring a dataset from a permanent area to a WORK area, or from a WORK area and put the dataset into a permanent area.

One way of copying a SAS dataset from one directory to another, and to some is the most efficient, is to either use the COPY procedure, or the COPY statement in the DATASETS procedure.

The syntax for the COPY procedure, when copying data, is:

   PROC COPY IN=source-library OUT=target-library MEMTYPE=DATA;
      SELECT member-list;
      EXCLUDE member-list;
   RUN;

where

Source-library the libname pointing to the source directory
Target-library the libname pointing to the target directory

If the SELECT or EXCLUDE statements are not used then all datasets in the source directory will be copied to the target directory. If only select datasets are needed to be copied then the SELECT or EXCLUDE statements are useful - in the case of SELECT only those datasets that are listed will be copied, while in the case of EXCLUDE all datasets except those listed will be included.

The following example selects the dataset CLASS from the SASHELP library and copies it to the WORK library, maybe for later manipulation:

   PROC COPY IN=sashelp OUT=work MEMTYPE=data;
      SELECT class;
   RUN;

The PROC DATASETS equivalent call for the above example is:

   PROC DATASETS LIBRARY=work;
      COPY IN=sashelp OUT=work MEMTYPE=data;
      SELECT class;
      QUIT;
   RUN;
________________________________
Updated October 1, 2008