Chapter Contents

Previous

Next
COPY

COPY



Copies SAS data files

CMS specifics: use of LABEL= option


Copying Members to Sequential Libraries
Types of Label Processing
LABEL=LABOFF Processing
LABEL=NL Processing
LABEL=SL Processing
See Also


Copying Members to Sequential Libraries

When copying members to a sequential library, any existing members in the library are normally lost. The copied members replace the existing members. To preserve existing members in the destination sequential library, you can choose to append copied members to the end of the sequential library without checking for duplicate members. To do so, you need to allocate the destination library using the DISP=MOD option in the LIBNAME statement. This LIBNAME option is valid for libraries using the V6TAPE or later engine, and this option applies only to the COPY procedure. When DISP=MOD is asserted on the destination sequential library, SAS does not check for duplicate members.

Appending new members without checking for duplicates means that the destination library can have two or more members with the same name after the copy. Only the first member in the library will be accessed by SAS. To ensure that all members can be accessed by SAS, use the EXCLUDE statement in the COPY procedure or, after the COPY procedure, use the REMOVE or RENAME statements in the DATASETS procedure. For further information, see SAS Procedures Guide.

For further information on sequential tape processing, see Working with SAS Files on Tape.


Types of Label Processing

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.

LABEL=LABOFF Processing

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


LABEL=NL Processing

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 sequential file to be opened. You do not need to use the CMS TAPE command to position the tape; when SAS opens the sequential 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 sequential file. If you omit this step, output to that tape library overwrites the existing physical sequential 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

  1. 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;                            

  2. 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;                            

  3. copying a SAS data library to tape as a second sequential 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 */

  4. 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.  [cautionend]

LABEL=SL Processing

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 sequential file to be opened. You do not need to use the CMS TAPE command to position the tape; when SAS opens the sequential 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 sequential file. If you omit this step, output to that tape library overwrites the existing physical sequential 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

  1. 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;                            

  2. 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;                            

  3. copying a SAS data library to tape as a second sequential 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;                            

  4. 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.  [cautionend]


See Also


Chapter Contents

Previous

Next

Top of Page

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