Return to Archive

SAS Tip of the Month
December 2008

A couple of months ago I used the COPY and DATASETS procedure to copy a dataset from one library to another, but what if instead we wanted to make a copy of a dataset in the same directory, e.g. take the dataset CLASS (that was already copied from the SASHELP directory to the WORK directory) and make it CLASSCOPY (maybe we want to manipulate it without effecting the original dataset).

You can certainly use a datastep as given in the following following example:

   DATA classcopy;
      SET class;
   RUN;

But another way is to use the AGE statement in the DATASETS procedure as given below:

   PROC DATASETS LIBRARY=work;
      AGE class classcopy;
      QUIT;
   RUN;

Using the AGE statement will make a copy of the dataset CLASS and name it CLASSCOPY - if CLASSCOPY already exists then it will be overwritten by the data in CLASS.

While this example is not a use that I would see very useful, it does have one other application. When creating a number of datasets that we put into a permanent area, it is useful to have a copy of the previous version for QC purposes, as the following example demonstrates:

   PROC DATASETS LIBRARY=derived_data;
      AGE ae ae_prevversion;
      COPY IN=WORK OUT=derived_data;
         SELECT ae;
      QUIT;
   RUN;

In the example above, before the latest version of AE is put into the DERIVED_DATA library, a copy is made and named AE_PREVVERSION - this then can be used to compare against the latest version AE and see that changes expected actually occurred.

________________________________
Updated December 1, 2008