COPY Statement
Copies
all or some of the SAS files in a SAS data library.
COPY
OUT=libref-1
<CLONE|NOCLONE>
<CONSTRAINT=YES|NO>
<IN=libref-2>
<INDEX=YES|NO>
<MEMTYPE=(mtype(s))>
<MOVE
<ALTER=alter-password>>
;
|
- OUT=libref
- names the SAS data library to copy SAS files to.
- 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.
- CLONE|NOCLONE
- specifies whether to copy the following data set attributes:
- size of input/output buffers
- whether the data set is
compressed
- whether free space is reused.
You specify these attributes with either data set options or SAS system
options:
- BUFSIZE= value for the size of the input/output buffers
- COMPRESS= value for whether the data set is
compressed
- REUSE= value for whether free space is reused.
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.
- 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.
- 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: |
|
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 .
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;
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.
The MEMTYPE= option in the COPY statement differs from the MEMTYPE=
option in other statements in the procedure in several ways:
- A slash does not precede the option.
- You cannot enclose the MEMTYPE= option in
parentheses to limit
its effect to the member immediately preceding it.
- The SELECT and EXCLUDE statements and the IN= option (in the COPY
statement) affect the behavior of the MEMTYPE= option in the COPY statement
according to the following rules:
- MEMTYPE= in a SELECT or EXCLUDE statement takes precedence over
the MEMTYPE= option in the COPY statement. The following statements copy
only VISION.CATALOG and NUTR.DATA from the default data library to the DEST
data library; the MEMTYPE= value in the first SELECT statement overrides the
MEMTYPE= value in the COPY statement.
proc datasets;
copy out=dest memtype=data;
select vision(memtype=catalog)
nutr;
run;
- If you do not use the IN= option, or you use it to specify the
library that happens to be the procedure input library, the value of the MEMTYPE=
option in the PROC DATASETS statement limits the types of SAS files that are
available for processing. The procedure uses the order of precedence described
in rule 1 to further subset the types available for copying. The following
statements do not copy any members from the default data library to the DEST
data library; instead, the procedure issues an error message because the MEMTYPE=
value specified in the SELECT statement is not one of the values of the MEMTYPE=
option in the PROC DATASETS statement.
/* This step fails! */
proc datasets memtype=(data program);
copy out=dest;
select apples / memtype=catalog;
run;
- If you specify an input data library in the IN= option other than
the procedure input library, the MEMTYPE= option in the PROC DATASETS statement
has no affect on the copy operation. Because no subsetting has yet occurred,
the procedure uses the order of precedence described in rule 1 to subset the
types available for copying. The following statements successfully copy BODYFAT.DATA
to the DEST data library because the SOURCE library specified in the IN= option
in the COPY statement is not affected by the MEMTYPE= option in the PROC DATASETS
statement.
proc datasets library=work
memtype=catalog;
copy in=source out=dest;
select bodyfat / memtype=data;
run;
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.
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.
Generally, the COPY procedure functions the same as the COPY
statement in the DATASETS procedure. The two differences are
- The IN= argument is required with PROC COPY. In the COPY statement,
IN= is optional. If omitted, the default value is the libref of the procedure
input library.
- PROC DATASETS cannot work with libraries that allow only sequential
data access.
You
can use the COPY statement to copy generation groups. However, you cannot
copy individual generation files.
Typically, you use PROC COPY to transport SAS data sets between hosts.
See The COPY Procedure for more information and an
example.
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.