Chapter Contents

Previous

Next
The DATASETS Procedure

COPY Statement


Copies all or some of the SAS files in a SAS data library.

Featured in: Manipulating SAS Files


COPY OUT=libref-1
<CLONE|NOCLONE>
<CONSTRAINT=YES|NO>
<IN=libref-2>
<INDEX=YES|NO>
<MEMTYPE=(mtype(s))>
<MOVE <ALTER=alter-password>> ;


Required Arguments

OUT=libref
names the SAS data library to copy SAS files to.
Aliases: OUTLIB= and OUTDD=
Featured in: Manipulating SAS Files


Options

ALTER=alter-password
provides the alter password for any alter-protected SAS files that you are moving from one data library to another. Because the MOVE option deletes the SAS file from the original data library, you need alter access to move the SAS file.
See also: Using Passwords with the DATASETS Procedure

CLONE|NOCLONE
specifies whether to copy the following data set attributes:

You specify these attributes with either data set options or SAS system options:

For the BUFSIZE= attribute, CLONE and the BUFSIZE= Attribute summarizes how the COPY statement works:

CLONE and the BUFSIZE= Attribute
If you use... the COPY statement...
CLONE uses the BUFSIZE= value from the input data set for the output data set.
NOCLONE uses the current setting of the SAS system option BUFSIZE= for the output data set.
neither determines the type of access method, sequential or random, used by the engine for the input data set and the engine for the output data set. If both engines use the same type of access, the COPY statement uses the BUFSIZE= value from the input data set for the output data set. If the engines do not use the same type of access, the COPY statement uses the setting of SAS system option BUFSIZE= for the output data set.

For the COMPRESS= and REUSE= attributes, CLONE and the COMPRESS= and REUSE= Attributes summarizes how the COPY statement works:

CLONE and the COMPRESS= and REUSE= Attributes
If you use... the COPY statement...
CLONE uses the values from the input data set for the output data set. If the engine for the input data set does not support the COMPRESS= or REUSE= attribute, the COPY statement uses the current setting of the corresponding SAS system option.
NOCLONE uses the current setting of the SAS system options COMPRESS= or REUSE= for the output data set.
neither defaults to CLONE.

CONSTRAINT=YES|NO
specifies whether to copy all integrity constraints when copying a data set.
Default: NO

IN=libref
names the SAS data library containing SAS files to copy.
Aliases: INLIB= and INDD=
Default: the libref of the procedure input library

INDEX=YES|NO
specifies whether to copy all indexes for a data set when copying the data set to another SAS data library.
Default: YES

MEMTYPE=(mtype(s))
restricts processing to one or more member types.
Aliases: MT=, MTYPE=
Default: If you omit MEMTYPE= in the PROC DATASETS statement, the default is MEMTYPE=ALL.
See also:
Specifying Member Types When Copying or Moving SAS Files
Member Types
Featured in: Manipulating SAS Files

MOVE
moves SAS files from the input data library (named with the IN= option) to the output data library (named with the OUT= option) and deletes the original files from the input data library.
Restriction: The MOVE option can be used to delete a member of a SAS library only if the IN= engine supports the deletion of tables. A tape format engine does not support table deletion. If you use a tape format engine, SAS suppresses the MOVE operation and prints a warning.
Featured in: Manipulating SAS Files

NOCLONE
See the description of CLONE .


Copying an Entire Library
To copy an entire SAS data library, simply specify an input data library and an output data library. For example, the following statements copy all the SAS files in the SOURCE data library into the DEST data library:

   proc datasets library=source;
      copy out=dest;
   run;


Copying Selected SAS Files
To copy selected SAS files, use a SELECT or EXCLUDE statement. For more discussion of using the COPY statement with a SELECT or an EXCLUDE statement, see Specifying Member Types When Copying or Moving SAS Files and see Manipulating SAS Files for an example.


Specifying Member Types When Copying or Moving SAS Files
The MEMTYPE= option in the COPY statement differs from the MEMTYPE= option in other statements in the procedure in several ways:


Copying Password-Protected SAS Files
You can copy a password-protected SAS file without specifying the password. However, because the password continues to correspond to the SAS file, you must know the password in order to access and manipulate the SAS file after you copy it.


Copying Data Sets with Long Variable Names
If the VALIDVARNAME=V6 option is set and the data set has long variable names, the long variable names are truncated, unique variables names are generated, and the copy succeeds. If VALIDVARNAME=ANY or V7, the copy fails with an error if the OUT= engine does not support long variable names.

When a variable name is truncated, the variable name is shortened to eight bytes. If this name has already been defined in the dataset, the name is shortened and a digit is added, starting with the number 2. The process of truncation and adding a digit continues until the variable name is unique. For example, a variable named LONGVARNAME becomes LONGVARN, provided that a variable with that names does not already exist in the data set. In that case, the variable names becomes LONGVAR2.

CAUTION:
Truncated variable names can collide with names already defined in the input data set. This is possible when the variable name that is already defined is exactly eight bytes long and ends in a digit. In that case, the truncated name is defined in the output data set and the name from the input data set is changed. For example,
options validvarname=v7;
data test;
   lonvar10='aLongVariableName';
   retain longvar1-longvar5 0;
run;
options validvarname=v6;
proc copy in=work out=sasuser;
   select test;
run;
In this example, LONGVAR10 is truncated to LONVAR1 and placed in the output data set. Next, the original LONGVAR1 is copied. Its name is no longer unique and so it is renamed LONGVAR2. The other variables in the input data set are also renamed according to the renaming algorithm.  [cautionend]


Using the COPY Procedure Instead of the COPY Statement
Generally, the COPY procedure functions the same as the COPY statement in the DATASETS procedure. The two differences are


Copying Generation Groups
You can use the COPY statement to copy generation groups. However, you cannot copy individual generation files.


Transporting SAS Data Sets between Hosts
Typically, you use PROC COPY to transport SAS data sets between hosts. See The COPY Procedure for more information and an example.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.