Chapter Contents

Previous

Next
SAS Companion for the OpenVMS Operating Environment

Accessing External Files on Tape

An external file can reside on either a labeled tape or an unlabeled tape. This section discusses the DCL commands that you use when you access external files that are stored on tape. It then describes how to write to and read from external files on labeled and unlabeled tapes.

Note:   You cannot use wildcards in tape specifications, nor can you use concatenated tape specifications.  [cautionend]


DCL Commands for Tape Access

Use the following DCL commands to request and then release the tape drive and volume for your SAS job or session. You can issue these commands either before you invoke the SAS System or in the X statement after you invoke the SAS System.

ALLOCATE device-name<logical-name>
requests exclusive use of the tape drive on which the tape volume is physically mounted, and it optionally establishes logical-name. This command is not required; however, you do not have exclusive use of your device until you issue the ALLOCATE command.

INITIALIZE </qualifier> device-name volume-label
initializes the tape and specifies a label to assign to the tape. Use the INITIALIZE command only when you are writing to a tape for the first time. For more information about initializing tapes, refer to Guide to VMS Files and Devices.

MOUNT </qualifier> device-name <volume-label>
requests that the tape be mounted on the tape drive identified by device-name. If the tape is treated as ANSI-labeled, then you must include the volume label of the mounted tape. The syntax of the MOUNT command for a labeled tape is

$ MOUNT device-name volume-label
where volume-label has a maximum length of six characters.

If the tape is unlabeled, then you must include the /FOREIGN qualifier and the device name. The syntax of the MOUNT command for an unlabeled tape is

$ MOUNT/FOREIGN device-name

You do not need to use volume-label when requesting an unlabeled tape.

If you are requesting an unlabeled tape, you can issue the following form of the MOUNT command, which tells the computer operator which tape to mount:

$ MOUNT/ASSIST/COMMENT=
"instructions" device-name
where instructions tell the computer operator which tape to mount, and device-name identifies the tape drive.

If you are writing or reading records of a different length than the default block size, you can use the /BLOCKSIZE= qualifier to specify the block size. For example, in the following form of the MOUNT command, xxxx specifies the appropriate block size for an unlabeled tape:

$ MOUNT/FOREIGN/BLOCKSIZE=
xxxx device-name

After you issue the MOUNT command for a labeled or unlabeled tape, your keyboard locks until the MOUNT command executes (that is, until the operator mounts the tape). This command is required.

SET MAGTAPE </qualifier> device-name
assigns special characteristics to a tape device. Qualifiers include the following:

/DENSITY=
sets the density of 800, 1,600, or 6,250 bpi (bytes per inch) for foreign tape operations.

/REWIND
rewinds the tape.

/SKIP=FILES: n
specifies the number of files (n) to skip over on an unlabeled tape.

DISMOUNT </NOUNLOAD> device-name
dismounts a labeled or unlabeled tape. When you issue the DISMOUNT command, the tape is physically unloaded by default. In order to mount and use the tape again, operator intervention is required. Use the /NOUNLOAD qualifier to prevent the default unload operation.

DEALLOCATE device-name
releases the tape drive from your job or session.

In each of these commands, device-name can be either the name of a tape drive at your site (for example, MUA0:) or a logical pointing to the tape drive.

After you issue commands to request the device and tape volume, use the DCL DEFINE command, the SAS FILENAME statement, or the FILENAME function to associate an OpenVMS logical name or SAS fileref with the external file on tape. For a labeled tape, specify a file in one of the following two forms:

For an unlabeled tape, specify a file in one of the following two forms:

You can also use the SAS X statement to issue the DEFINE command.

The OpenVMS logical name or SAS fileref that is assigned to the tape device is then used as the file specification in the INFILE or FILE statement.

Note:   In these examples, it is assumed that the OpenVMS logical name definition for tapedevice includes a colon in the device specification, such as the following:

$ DEFINE TAPEDEVICE MUA0:

If your OpenVMS logical name definition does not include a colon, then you must specify the colon when you use TAPEDEVICE, as in the following:

filename fileref 'tapedevice:';
  [cautionend]

Order of Tape Access Commands

When you use the SAS X statement to issue the tape-access commands, specify the commands in the following order:

INITIALIZE
ALLOCATE
MOUNT

This order differs from the order that you use when you issue the same commands from the DCL prompt.

If you do not use this order, and you allocate the tape before you initialize it, a message warns you that the device has already been allocated to another user when you try to initialize the tape.

When you issue the tape-access commands from the DCL prompt, specify them in the following order:

ALLOCATE
INITIALIZE
MOUNT

Using Multivolume Tapes

If you plan to write to several tapes in a set, you must initialize all the tapes before you start your job. Then use the /INITIALIZE=CONTINUATION qualifier in the first MOUNT command, as in the following example:

$ ALLOCATE TAPEDEVICE
$ INITIALIZE TAPEDEVICE TAPELIB
$ MOUNT/INITIALIZE=CONTINUATION TAPEDEVICE TAPELIB
$ SAS
   . . . more SAS statements . . .

The /INITIALIZE=CONTINUATION qualifier guarantees that the appropriate number is added to the label as the OpenVMS system mounts the subsequent volumes. For example, the following MOUNT command first creates a tape labeled MYTAPE. Subsequent tapes are labeled MYTA02, MYTA03, MYTA04, and so on:

$ MOUNT/INITIALIZE=CONTINUATION $2$MUA2: MYTAPE

When you issue a request to mount the next relative volume, the operator issues the reply with the /INITIALIZE_TAPE=request-number option. For example, if you issue the following request:

Request 69 from user SMITH. Mount relative volume
MYTA02 on $2$MUA2:
the operator performs the following steps:
  1. Mounts an initialized tape on the drive.

  2. Issues the following command:
    $ REPLY/INITIALIZE_TAPE=69
    which sends the following message to user SMITH:
    Mount request 69 satisfied by operator

As this example illustrates, some coordination is required between the user and the operator when multivolume tapes are used. Contact your system manager for more information about this topic.


Writing to a Labeled Tape

The following example illustrates a SAS program (submitted in an interactive line mode session) that writes to a labeled tape for the first time:

$ ALLOCATE TAPEDEVICE
$ INITIALIZE TAPEDEVICE LABEL1
$ MOUNT TAPEDEVICE LABEL1
$ DEFINE OUTTAPE TAPEDEVICE:EXPGIFTS.DAT
$ SAS
   . . . notes and messages to SAS log . . .
1? data _null_;
2? input gift $ price;
3? file outtape;
4? if price>100 then
5? put gift price;
6? datalines;
7> watch 250.00
8> clown 35.31
   . . . more data lines . . .
15> ;
   . . .  notes and messages to SAS log . . .
16? x 'dismount tapedevice';
17? x 'deallocate tapedevice';
18?

This program writes the file EXPGIFTS.DAT to the tape that is identified by the label LABEL1. (The tape is referenced by the fileref OUTTAPE in the FILE statement.) After the write operation, the tape remains positioned at the end of the first file, ready to write another file. When you issue the DISMOUNT and DEALLOCATE commands, the tape is rewound and physically unloaded, and the drive and tape are released from your SAS session.

The default block size for an ANSI-labeled tape is 2,048 bytes.


Writing to an Unlabeled Tape

When you are writing to an unlabeled tape, you must use the /FOREIGN qualifier in the MOUNT command:

$ MOUNT/FOREIGN TAPEDEVICE

You must also use special values for the RECFM= and LRECL= options in the FILE statement, as shown in the following example:

$ ALLOCATE TAPEDEVICE
$ INITIALIZE TAPEDEVICE
$ MOUNT/FOREIGN TAPEDEVICE
$ DEFINE OUTTAPE TAPEDEVICE
$ SAS
  . . . notes and messages to SAS log . . .
1? data _null_;
2? input gift $ price;
3? file outtape recfm=d lrecl=80;
4? if price>100 then
5? put gift price;
6? datalines;
7> watch 250.00
8> clown 35.31
  . . . more data lines . . .
15> ;
  . . . notes and messages to SAS log . . .
16? x 'dismount outtape';
17? x 'deallocate outtape';
18?

The default block size for an unlabeled tape is 512 bytes. If you want to write a record that is longer than the default block size, you must increase the block size by using the /BLOCKSIZE qualifier in the MOUNT command. For example, the following command increases the block size to 8000 bytes for an unlabeled tape:

$ MOUNT/FOREIGN/BLOCKSIZE=8000 TAPEDEVICE LABEL1

If you attempt to write a record that is longer than the block size, you receive the following error message:

ERROR: Tape block size less than LRECL specified.

To write to an unlabeled tape from the DATA step, you must indicate the tape format by using RECFM=D. If you do not use RECFM=D for this type of access, the results are unpredictable.

You must also use the LRECL= option to indicate the length of each record. If the records that you are writing are variable-length records, then use a value for the LRECL= option that is the maximum record length. The minimum LRECL= value is 14. This minimum value is the only restriction on the LRECL= value for unlabeled tapes.


Reading from a Labeled Tape

When the SAS System reads a file from a labeled tape, it searches for a filename on the tape that matches the filename used in the DEFINE command or FILENAME statement. The following example illustrates reading an external file from a labeled tape to create a SAS data set:

$ ALLOCATE TAPEDEVICE
$ MOUNT TAPEDEVICE LABEL1
$ DEFINE INTAPE TAPEDEVICE:EXPGIFTS.DAT
$ SAS
  . . . notes and messages to SAS log . . .
1? data expenses;
2?    infile intape;
3?    input gift $ price;
4? run;
  . . . notes and messages to SAS log . . .
5? x 'dismount tapedevice';
6? x 'deallocate tapedevice';
7?

The DATA step in this example reads a file named EXPGIFTS.DAT, which is located on the tape identified by the label LABEL1. (The file is referenced by the fileref INTAPE in the INFILE statement.) After the read operation, the tape is positioned at the start of the next file.


Reading from an Unlabeled Tape

When you read from an unlabeled tape, you must position the tape to the appropriate file because there is no filename for which to search. Remember that the DEFINE command or FILENAME statement for an unlabeled tape includes only the OpenVMS logical name or fileref, plus the name of the tape device. If you specify a filename, it is ignored.

Here are two ways of positioning a tape to the correct file:

The following example illustrates using a null DATA step to skip the first file on an unlabeled tape so that the second DATA step can read the next file:

$ ALLOCATE TAPEDEVICE
$ MOUNT/FOREIGN TAPEDEVICE
$ DEFINE MYTAPE TAPEDEVICE
$ SAS
  . . . notes and messages to SAS log . . .
1? data _null_;
2?    infile mytape recfm=d lrecl=80;
3?    input;
4? run;
  . . . notes and messages to SAS log . . .
5? data prices;
6?    infile mytape recfm=d lrecl=80;
7?    input name $ x y z;
8?    prod=x*y;
9?    if prod<z then output;
0? run;
  . . . notes and messages to SAS log . . .
5? x 'dismount mytape';
6? x 'deallocate mytape';
7?

The next example illustrates how to read the second file from the tape that is referenced by the OpenVMS logical name MYTAPE by using the SET MAGTAPE command with the /SKIP=FILES: n qualifier:

$ ALLOCATE TAPEDEVICE
$ MOUNT/FOREIGN TAPEDEVICE
$ DEFINE MYTAPE TAPEDEVICE
$ SAS
  . . . notes and messages to SAS log . . .
1? x 'set magtape mytape/skip=files:1';
2? data prices;
3?    infile mytape recfm=d lrecl=80;
4?    input name $ x y z;
5?    prod=x*y;
6?    if prod<z then output;
7? run;
  . . . notes and messages to SAS log . . .
8? x 'dismount mytape';
9? x 'deallocate mytape';
10?

To read from an unlabeled tape from the DATA step, you must indicate the tape format by using RECFM=D. If you do not use RECFM=D for this type of access, the results are unpredictable.

You must also use the LRECL= option to indicate the length of each record. If the records that you are accessing are variable-length records, then use a value for the LRECL= option that is the maximum record length. The minimum LRECL= value is 14. This minimum value is the only restriction on the LRECL= value for unlabeled tapes.


Chapter Contents

Previous

Next

Top of Page

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