Chapter Contents

Previous

Next
SAS Companion for the CMS Environment

Working with SAS Files on Disk


Writing to SAS Files on Disk

To write a disk-format SAS file, you usually need only to specify the two-level filename in the appropriate SAS statement. That is, in most cases you do not need to assign a libref to the file because SAS automatically assigns librefs for permanent SAS files on disk. (However, see When to Assign a Libref for a SAS File on Disk for exceptions and for performance considerations.) For example, suppose you specify the SAS filename MYLIB.TASTEST in a SAS statement. In CMS terms, this is equivalent to filename TASTEST and filetype MYLIB:

SAS name
CMS name
MYLIB.TASTEST
TASTEST MYLIB
libref.filename
filename filetype

Because the SAS filename includes no filemode or directory identifier, SAS uses the following procedure to determine where to write the file:

  1. First SAS checks to see whether the libref MYLIB was previously assigned by a SAS LIBNAME statement or function and is still in effect. If so, SAS writes the new file to the minidisk or SFS directory that was indicated by the LIBNAME statement or function.

  2. If MYLIB is not a current libref, then SAS checks to see whether MYLIB was previously assigned as a DDname by a CMS FILEDEF command and is still in effect. If so, SAS writes the new file to the minidisk or SFS directory that was indicated by the FILEDEF command.

  3. If MYLIB is neither a current libref nor a current DDname, then SAS searches all accessed minidisks or SFS directories (in the standard search order) to see if there are any SAS files that have the filetype MYLIB. To do this, SAS must read each file to determine whether it is a SAS file. In some cases this can cause significant overhead, which can be avoided by using the LIBNAME statement or function. If SAS finds a SAS file with the filetype MYLIB, then it writes the new file to the same minidisk or SFS directory (unless the minidisk is accessed as READ-only, and then an error message is issued).

  4. If no matching filetype is found, then SAS writes the file to the first R/W disk, using the libref MYLIB as the filetype.


Reading SAS Files on Disk

To read an existing SAS file that is in disk format, you usually need only to specify the two-level filename in the appropriate SAS statement. That is, in most cases, you do not need to assign a libref to the file. (However, see When to Assign a Libref for a SAS File on Disk for exceptions and performance considerations.) For example, suppose you specify the SAS file MYLIB.TASTEST in a SAS statement. In CMS terms, this is equivalent to filename TASTEST and filetype MYLIB:

SAS name
CMS name
MYLIB.TASTEST
TASTEST MYLIB
libref.filename
filename filetype

Because the SAS filename includes no filemode or directory identifier, SAS uses the following procedure to locate the file:

  1. First SAS checks to see whether the libref MYLIB was previously assigned by a SAS LIBNAME statement or function and is still in effect. If so, SAS refers to the minidisk or SFS directory that was indicated by the LIBNAME statement or function.

  2. If MYLIB is not a current libref, then SAS checks to see whether MYLIB was previously assigned as a DDname by a CMS FILEDEF command and is still in effect. If so, SAS refers to the minidisk or SFS directory that was indicated by the FILEDEF command.

  3. If MYLIB is neither a current libref nor a current DDname, then SAS searches all accessed minidisks or SFS directories (in the standard search order) to locate the file TASTEST MYLIB.

    Note:   If the file exists on more than one minidisk or directory, SAS stops searching as soon as it finds the first TASTEST MYLIB file. If you have multiple files with the same name and filetype on different minidisks or directories, and you want to read a file that would not be located first according to the standard search order, then you must assign and use a libref.  [cautionend]


When to Assign a Libref for a SAS File on Disk

Under CMS, when you are reading from and writing to disk, you do not always have to assign a libref. (See Reading SAS Files on Diskand Writing to SAS Files on Disk for explanations of why librefs generally are not required for disk-format files.) You may want to do so, though, for portability and clarity.

In the following examples, filemode can be specified in either of two ways:

You should assign a libref under the following circumstances:


Chapter Contents

Previous

Next

Top of Page

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