Chapter Contents


SAS Companion for the OpenVMS Operating Environment

Accessing SAS Files on Tape

This section discusses accessing, reading, and writing SAS files on tape. There are also some notes on tape usage.

DCL Commands for Tape Access

In order to write to a tape in a SAS job, you can issue the following DCL commands to allocate the tape drive and mount the appropriate tape volume. You must issue these commands in the order shown:

$ ALLOCATE tape-device:
$ INITIALIZE tape-device:  volume-label
$ MOUNT tape-device:  volume-label

Note:   If you are writing SAS files to tape with the TAPE engine, you must mount the tape as a labeled Files-11 tape. A labeled Files-11 tape has header information preceding each file. An unlabeled, or foreign, tape does not have this header information. The TAPE engine can process only labeled Files-11 tapes. For more information about Files-11 tapes, refer to Guide to OpenVMS Files and Devices.  [cautionend]

Issue the INITIALIZE command only if you are writing to a tape for the first time. When a tape is initialized, any files that were previously stored on the tape are no longer accessible. Therefore, use the ALLOCATE and MOUNT commands when you want to read from a tape or write additional files to a tape; do not reinitialize the tape.  [cautionend]
The volume label that you specify in the INITIALIZE command must be used subsequently in the MOUNT command in order to access the tape. After you have issued the appropriate commands to access the tape, you must then use the LIBNAME statement to associate a libref with the tape.

When your SAS job finishes, issue the following commands to release the tape drive from your terminal session:

$ DISMOUNT tape-device:
$ DEALLOCATE tape-device:

Any of these commands can also be issued in the X statement. However, if you use the X statement, you must issue the INITIALIZE command before the ALLOCATE command. The reverse order is not supported when you use the X statement.

Accessing Multivolume Tapes

When creating SAS files on multivolume tapes, you must initialize the tapes before you write the files to the tapes. If you do not initialize the tapes first, the operating environment will not recognize them as part of the same volume set. When you mount the first volume of the set, use the following MOUNT command:

_$ tape-device: label

This command instructs the OpenVMS system to add a continuation number to each label as it creates the multivolume set. For example, if you have a series of tapes initialized to MYTAPE and use drive MUA0:, use the following command:


When the first volume is filled, the operating environment prompts the operator to mount MYTA02. The OpenVMS system adds a sequencing number to the tape label. As tape labels are limited to six characters, the original label, if it exceeds this number, can be truncated when the continuation number is added.

Reading and Writing SAS Files on Tape

In addition to the appropriate DCL commands, use the LIBNAME statement or the New Library dialog box to associate a libref with the tape when reading or writing SAS files. The following is an example of the LIBNAME statement:

libname sample tape 'mua0:';

Then use the libref SAMPLE in the appropriate SAS statements to refer to the tape. The following is an example:

data sample.oldstat;
   set status;

A libref associated with a tape drive signals that the file to be read or written is in sequential format.

Note:   You can also write SAS files in sequential format on disk if you define the libref to a disk location, but use the sequential engine (TAPE) in the LIBNAME statement or in the New Library dialog box.  [cautionend]
The tape can contain one or more SAS files. When you read or write a file on tape, you use a two-level name; the first level is a libref that refers to the tape, and the second level names the SAS file to be read or written. The following is an example of the LIBNAME statement:

libname mytape 'mua0:';
data diskds1;
   set mytape.ds1;

This program reads a data set with the filename DS1.SAS7SDAT from the tape referenced by the libref MYTAPE.

You can write SAS files with duplicate names to the same tape. For example, you can have more than one SAS data set named DS1 on a tape. When you read the data set named DS1, the first (and possibly the oldest) version of DS1 found on the tape is the version read. The first version found depends on the current position of the tape.

Notes on Tape Usage

Use the COPY procedure to copy existing SAS files from disk to tape. The following is an example:

libname mydisk '[dir1]';
libname mytape tape 'mua0:';
proc copy in=mydisk out=mytape;

This procedure is often simpler to use than the DCL COPY command when moving SAS files to tape. Also, SAS log notes document the files copied. You can also use the DCL DIRECTORY command to list the SAS files on a labeled tape after it has been created.

When you use the DCL COPY command to move sequential format files created on disk to tape, you must create the files with a page size of 512 bytes and mount the tape with a block size of 512 bytes. The following example creates a sequential format data set on disk. It then shows how to copy it to tape and access it from within the SAS System.

As a first step, create the data set on disk using the sequential engine, with a page size of 512 bytes. Use the BUFSIZE= data set option to set the page size:

libname seqdisk tape '[dir]';
data seqdisk.a(bufsize=512);
   ... more DATA step statements ...

Now mount the tape with a block size of 512 bytes and copy the file to tape by issuing the following commands:


You can now access this data set directly from within the SAS System, as in the following statements:

libname seq tape 'mua0:';
proc contents data=seq.a;

If you can, it is far more efficient to create the data set on tape within the SAS System, using the TAPE engine. Use the DCL COPY command only when you have no other alternative. The advantage of using the TAPE engine instead of the DCL COPY command is that when you use the TAPE engine, you can use larger page sizes and block sizes. This means that I/O is more efficient because you can process the data in larger chunks.

To convert the data sets currently in disk format to sequential format before using the COPY command to move them to tape, you can use the following steps:

libname mydisk '[dir1]';
libname mytape tape '[dir2]';
data mytape.a;
   set mydisk.a;

If you store the files on an unlabeled tape, they must be restored to disk before the SAS System can access them.

Chapter Contents



Top of Page

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