Copies SAS data files
| CMS specifics: |
use of LABEL= option
|
The examples that follow illustrate
some basic tape operations and different types of label processing. These
examples use PROC COPY to transfer data libraries to tape.
Note:
A SAS data library on tape is defined as a tape file.
The type of tape label
processing that you choose has
a fundamental effect on how you use tapes. To specify how you want label
processing done for your SAS program, you can use the LABEL= option in the
LIBNAME statement. The examples that follow show three common types of label
processing:
The SAS System under CMS follows the
defaults for the
CMS FILEDEF command, and therefore the default for this option is LABEL=LABOFF.
However, to reduce the risk of error, SAS Institute recommends using LABEL=NL
for nonlabeled tapes. Always use LABEL=SL for labeled tapes. SAS Institute
also recommends avoiding the use of the CMS FILEDEF command with SAS and instead
using the LIBNAME statement.
If you
specify the LABEL=LABOFF option in the LIBNAME statement, you assume all responsibility
for positioning the tape before reading or writing a file. SAS begins reading
or writing to the tape at its current position. Use CMS TAPE commands (TAPE
REW, TAPE FSF, TAPE BSF) to position the tape to the correct point. Note
that when you issue CMS TAPE FSF or CMS TAPE BSF, your tape is positioned
on just the other side of the tape mark from
where you started. You should first reissue the LIBNAME statement before issuing
any CMS TAPE commands that change the position of the tape. Reissuing the
LIBNAME statement clears internal data structures that are kept by SAS and
that are invalidated by moving the tape. If there is any uncertainty about
tape position, issue CMS TAPE REW to start from a known point, the beginning
of the tape.
After SAS reads or writes a tape library, the tape is
positioned just after the end-of-file tape mark for that tape library. An
exception is that if an error occurs during tape I/O, the tape remains positioned
at the point of the error, and not past the tape mark. Normal output is terminated
with a single tape mark. After your final output, you should issue CMS TAPE
WTM to ensure that the tape ends with a double tape mark.
If you write to a tape library and then want to append
to the same tape library, you must issue CMS TAPE BSF so that the tape mark
that ends the first output is overwritten. Otherwise, this tape mark separates
the two outputs into two tape libraries. When you write data to a tape, everything
from that point that was formerly on the tape becomes unusable. Therefore,
take extreme care in positioning the tape.
To reread a tape library you have just read or written,
manually position the tape to the desired location. To do this, reissue the
LIBNAME statement, and then issue CMS TAPE commands to position the tape.
Some tape processing examples using LABEL=LABOFF include
With the LABEL=NL n option of the LIBNAME statement, you specify
the sequential number of the file on the tape. For example LABEL=NL 3 causes
the third tape file to be opened. You do not need to use the CMS TAPE command
to position the tape; when SAS opens the tape file, CMS automatically rewinds
the tape and positions it to the specified file. Because the tape is rewound
during positioning, it will be positioned correctly regardless of the prior
tape position.
After SAS reads or writes a tape library, the tape is
positioned just after the end-of-file tape mark for that tape library. Output
is terminated with a double tape mark; you do not need to write an additional
tape mark.
If you do output to a tape library and then want to
append to the same tape library, simply continue to use the existing libref.
Do not reissue the LIBNAME statement. Likewise, once you have read from or
written to a tape library, if you then want to reread it, no special steps
are required.
If you want to use PROC COPY to append to a tape library
that was written in a previous SAS session or for which the libref has been
deassigned, you must do something in the current SAS session to cause SAS
to read the entire existing tape library (for example, PROC CONTENTS).
This step appends subsequent output to that tape library to the end of the
physical tape file. If you omit this step, output to that tape library overwrites
the existing physical tape file.
In one special case, CMS TAPE commands are needed with
LABEL=NL. To initialize a new tape for LABEL=NL processing, you must issue
cms tape rew;
cms tape wtm 2;
Otherwise, the tape could run off the end.
Some tape processing examples using LABEL=NL include
-
copying a SAS data library to a new tape:
/* insure tape position */
cms tape rew;
/* initialize tape */
cms tape wtm 2;
/* specify file 1 */
libname tapeout 'tap1' label=nl 1;
/* copy SAS data library */
proc copy in=lib1 out=tapeout;
/* from lib1 to tape */
run;
-
copying multiple SAS data libraries to a single
SAS data library on a new tape:
/* insure tape position */
cms tape rew;
/* initialize tape */
cms tape wtm 2;
/* specify file 1 */
libname tapeout 'tap1' label=nl 1;
/* copy lib1 to tape */
proc copy in=lib1 out=tapeout;
/* copy lib2 to the */
proc copy in=lib2 out=tapeout;
/* same tape library */
run;
-
copying a SAS data library to tape as a second
tape file (following a preexisting file):
/* specify file 2 */
libname tapeout 'tap1' label=nl 2;
/* copy SAS data library */
proc copy in=lib2 out=tapeout;
/* from lib2 to a */
run;
/* separate tape library */
-
appending a SAS data library to an existing SAS
data library on a tape:
/* specify file 1 */
libname tapeout 'tap1' label=nl 1;
/* read the library */
proc contents data=tapeout._all_ nods;
run;
/* append SAS data library*/
proc copy in=lib3 out=tapeout;
/* from lib3 to tape */
run;
Note:
PROC CONTENTS is used to force
SAS to load the tape's library structure so that PROC COPY will append rather
than overwrite.
Like LABEL=NL, LABEL=SL frees you from the need to position the tape manually.
Standard label processing has advantages that are beyond the scope of this
discussion.
With the LABEL=SL n option of the LIBNAME
statement, you specify the sequential number of the file on the tape. For
example, LABEL=SL 3 causes the third tape file to be opened. You do not need
to use the CMS TAPE command to position the tape; when SAS opens the tape
file, CMS automatically rewinds the tape and positions it to the specified
file. Because the tape is rewound during positioning, it will be positioned
correctly regardless of the prior tape position.
If you do output to a tape library and then want to
append to the same tape library, continue to use the existing libref. Do not
reissue the LIBNAME statement. Likewise, once you have read from or written
to a tape library, if you then want to reread it, no special steps are required.
If you want to use PROC COPY to append to a tape library
that was written in a previous SAS session, or for which the libref has been
deassigned, you must cause SAS to read the entire existing tape library (for
example, PROC CONTENTS). This step appends subsequent output to that tape
library to the end of the physical tape file. If you omit this step, output
to that tape library overwrites the existing physical tape file.
In one special case, you may need CMS TAPE commands
with LABEL=SL. To initialize a new
tape for LABEL=SL processing, you must
submit the following statements:
cms tape rew;
cms tape wvol1 volid;
However if your tape is cataloged in a tape management
system, this step has probably been done for you automatically.
Some tape processing examples using LABEL=SL include
-
copying a SAS data library to a new tape:
/* specify file 1 */
libname tapeout 'tap1' label=sl 1
/* and identify VOLID */
volid=V00001;
/* copy SAS data library */
proc copy in=lib1 out=tapeout;
/* from lib1 to tape */
run;
-
copying multiple SAS data libraries to a single
SAS data library on a new tape:
/* specify file 1 */
libname tapeout 'tap1' label=sl 1
/* and identify VOLID */
volid=V00001;
/* copy lib1 to tape */
proc copy in=lib1 out=tapeout;
/* copy lib2 to the */
proc copy in=lib2 out=tapeout;
/* same tape library */
run;
-
copying a SAS data library to tape as a second
tape file (following a preexisting file):
/* specify file 2 */
libname tapeout 'tap1' label=sl 2
/* and identify VOLID */
volid=V00001;
/* copy SAS data library */
proc copy in=lib2 out=tapeout;
/* from lib2 to tape */
run;
-
appending a SAS data library to an existing SAS
data library on a tape:
/* specify file 1 */
libname tapeout 'tap1' label=sl 1
/* and identify VOLID */
volid=V00001;
proc contents data=tapeout._all_ nods;
/* read the library */
run;
/* append SAS data library*/
proc copy in=lib3 out=tapeout;
/* from lib3 to tape */
run;
Note:
PROC CONTENTS
is used to force SAS to load the tape's library structure so that PROC COPY
will append rather than
overwrite. ![[cautend]](../common/images/cautend.gif)
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.