|SAS Companion for UNIX Environments|
Tape devices are inherently slow and should be used on a regular basis only for archiving files or for transferring data from one system to another.
There are four UNIX commands that are frequently used to process tape files on UNIX:
|| positions the tape (winds forward
and rewinds). On AIX, this command is
||converts, reblocks, translates, and copies files.|
||concatenates, copies, and prints files.|
||saves and restores archive files.|
||connects to the specified host and executes the specified command.|
In addition, you will almost always need to use a no-rewind device and the SAS system option TAPECLOSE=LEAVE to get the results you want. The example in this section assume the use of a no-rewind device and TAPECLOSE=LEAVE.
You can use either the TAPE device type or the PIPE device type to process tape files.
|Using the TAPE Device Type|
To use the TAPE device type, enter the FILENAME statement as follows:
|FILENAME fileref TAPE 'tape-device-pathname' <options>;|
For example, this FILENAME statement associates YR1999
with a file stored on a tape that is mounted on device
filename yr1999 tape '/dev/tp0';
|Using the PIPE Device Type|
can also use the PIPE device type together with UNIX
dd command to process the tape:
|FILENAME fileref PIPE 'UNIX-commands';|
Using the PIPE device type and the
dd command can process the tape more efficiently
than the TAPE device type, and it allows you to use remote tape drives. However,
using UNIX commands in your application means that the application will have
to be modifed if it is ported to a non-UNIX environment.
For example, the following DATA step writes an external file to tape:
options tapeclose=leave; x 'mt -t /dev/rmt/0mn rewind'; filename outtape pipe 'dd of=/dev/rmt/0mn 2> /dev/null'; data _null_; file outtape; put '1 one'; put '2 two'; put '3 three'; put '4 four'; put '5 five'; run;The following DATA step reads the file from tape:
options tapeclose=leave; x 'mt -t /dev/rmt/0mn rewind'; filename intape pipe 'dd if=/dev/rmt/0mn 2> /dev/null'; data numbers; infile intape pad; input digit word $8.; run;
If the tape drive that you want to access is a remote
tape drive, you can access the remote tape drive by adding
to the X and FILENAME statements. For example, if the remote machine name
wizard, then you could
read and write tape files on
wizard by modifiying the X and FILENAME statements as follows:
x 'remsh wizard mt -t /dev/rmt/0mn rewind'; filename intape pipe 'remsh wizard \ dd if=/dev/rmt/0mn 2> /dev/null';
|Working with External Files Created on the Mainframe|
There are three main points to remember when dealing with tapes on UNIX that were created on a mainframe:
/dev/rmt/0mn) and the
mtcommand with the
fsf countsubcommand to position the tape to the desired user data file. The formula for calculating
count = (3 x user_data_file_number) - 2
ddcommand. After all of the tapes have been unloaded, you can use the
catcommand to concatenate all of the pieces in the correct order. You can then process the concatenated file on disk.
ddcommand, you must also specify the block size with the
ibssubcommand. For more information about host options on the INFILE statement, see INFILE. For more information about the
ibssubcommand, refer to the man page for the
|Example: Multi-volume, Standard Label Tapes|
Suppose that you are given a two-reel, multi-volume, standard label tape set containing a mainframe external file and told that the record length is 7 and the record format is fixed. You will need to unload the data portion of each tape into disk files, concatenate the two disk files, and process the resultant file.
Make sure that the first tape is in the tape drive,
then use the
to rewind the tape, skip over the label file, and position the tape at the
beginning of the user data file. In this case, the user data file that you
want to access is the first (and only) user data file on the tape. To skip
over the label and position the tape at the beginning of the user data file,
fsf count subcommand. Using the formula in Working with External Files Created on the Mainframe, the
fsf count value is 1.
mt -t /dev/rmt/0mn rewind mt -t /dev/rmt/0mn fsf 1 dd if=/dev/rmt/0mn of=/tmp/tape1 ibs=7Repeat this process with the second tape, then concatenate the two disk files into one file.
mt -t /dev/rmt/0mn rewind mt -t /dev/rmt/0mn fsf 1 dd if=/dev/rmt/0mn of=/tmp/tape2 ibs=7 cat /tmp/file1 /tmp/file2 > /tmp/ebcdic.numbersYou can then use the following DATA step to refer to the concatenated file (
/tmp/ebcdic.numbers) and to convert the data using the appropriate EBCDIC informats:
filename ibmfile '/tmp/ebcdic.numbers'; data numbers; infile ibmfile lrecl=7 recfm=f; length digit 8 temp $ 1 word $ 6; input temp $ebcdic1. word $ebcdic6.; digit=input(temp,8.); drop temp; run;
Top of Page
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.