Using External Files and Devices |
Using the PIPE Device Type |
You can use the PIPE device type together with the UNIX dd command to process a tape:
FILENAME fileref PIPE 'UNIX-commands'; |
The PIPE device type and the dd command enables you to use remote tape drives. However, using UNIX commands in your application means that the application will have to be modified if it is ported to a non-UNIX environment.
For example, the following DATA step writes an external file to tape:
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:
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 remsh computer-name or the following:
rsh computer-name
The above code is added to the X and FILENAME statements. For example, if the remote computer name is wizard , then you could read and write tape files on wizard by modifying 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:
UNIX does not support IBM standard label tapes. IBM standard label tapes contain user data files and labels, which themselves are files on the tape. To process the user data files on these tapes, use a no-rewind device (such as /dev/rmt/0mn) and the mt command with the fsf count subcommand to position the tape to the desired user data file. Here is the formula for calculating count :
count = (3 x user_data_file_number) - 2
UNIX does not support multivolume tapes. To process multivolume tapes on UNIX, the contents of each tape must be copied to disk using the dd command. After all of the tapes have been unloaded, you can use the cat command to concatenate all of the pieces in the correct order. You can then use SAS to process the concatenated file on disk.
You must know the DCB characteristics of the file. The records in files that are created on a mainframe are not delimited with end-of-line characters, so you must specify the original DCB parameters in the INFILE or FILENAME statement. In the INFILE statement, specify the record length, record format, and block size with the LRECL, RECFM, and BLKSIZE host options. In the FILENAME statement, if you use the PIPE device-type and the dd command, you must also specify the block size with the ibs subcommand. For more information about host options in the INFILE statement, see INFILE Statement: UNIX. For more information about the ibs subcommand, see to the man page for the dd command.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.