Previous Page | Next Page

Using SAS Files

Assigning OpenVMS Logical Names


How to Assign an OpenVMS Logical Name

There are some advantages to using the LIBNAME statement to identify your SAS libraries to SAS. (See Advantages of Using Librefs Rather than OpenVMS Logical Names.) However, you can also use an OpenVMS logical name for the same purpose. To assign an OpenVMS logical name, use the DCL DEFINE command.

Note:   Because you cannot specify an engine name in the DCL DEFINE command, SAS uses the procedure described in How SAS Assigns an Engine When No Engine Is Specified to determine which engine to use.  [cautionend]

To use an OpenVMS logical name to refer to a SAS library, you must define the logical name either outside SAS or from your SAS session using the X statement.


Example: Defining a Logical Name with the X Statement

You can assign the OpenVMS logical name MYLIB to the directory [MYDIR] in either of the following ways:


Using an OpenVMS Logical Name as a Libref

After assigning an OpenVMS logical name to a directory, you can use the logical name in a SAS job in the same way you would use a libref. Because the OpenVMS logical name is being used as a SAS name, it must follow the SAS naming conventions. For details about SAS naming conventions, see SAS Language Reference: Concepts.

The first time an OpenVMS logical name is used in this manner, SAS assigns it as a libref for the SAS library. The logical name is not listed by the LIBNAME LIST statement or listed in the SAS Explorer window until after you have used it in a SAS statement. (See Listing Your Current Librefs under OpenVMS.)

Note:   OpenVMS logical names that are defined in a subprocess are not recognized by the current SAS session. However, OpenVMS logical names that are defined in the OpenVMS parent process are available for use during the current session. For information about how to use the X statement or the X command to define an OpenVMS logical name in the OpenVMS parent process, see Issuing DCL Commands during a SAS Session.  [cautionend]


Examples: Using a Logical Name as a Libref in a DATA Step and Procedure

If you assigned the OpenVMS logical name MYLIB to a SAS library, you could then use MYLIB as a libref in a SAS DATA step:

data mylib.a;
   set mylib.b;
run;

Similarly, you could use the logical name as a libref in a SAS procedure:

proc contents data=mylib._all_;
run;


Using an OpenVMS Logical Name in the LIBNAME Statement


Associating an Engine with an OpenVMS Logical Name

Because you cannot specify an engine in the DCL DEFINE command, you might want to use the LIBNAME statement to specify an engine for a SAS library to which you previously assigned an OpenVMS logical name. You can use the logical name in place of the libref in a LIBNAME statement, as in this example, which associates the BASE engine with the logical name SEQACC:

libname seqacc base;


Associating a Libref and Engine with a Logical Name

If you specify the logical name in place of the SAS-library argument in a LIBNAME statement, then you can associate both a libref and an engine with the logical name. The following example associates the libref IN and the BASE engine with the library that is assigned the logical name SEQACC:

libname in base 'seqacc';


Specifying Library or Engine/Host Options with a Logical Name

You can also use the LIBNAME statement to specify library options that are valid in all operating environments, or engine/host options for a SAS library to which you previously assigned an OpenVMS logical name. The following example associates the libref RANDMACC and the CONCUR engine with a path that includes the logical name MYDISK. It specifies the portable library option ACCESS=:

libname randmacc concur 'mydisk:[mylib]' 
   access=readonly;


Using a Search-String Logical Name to Concatenate SAS Libraries

If you have several directories that you want to use as a single SAS library, you can define an OpenVMS search-string logical name to the list of libraries, and then use that logical name in your SAS programs. The list of libraries can include both directories and other logicals.


Order in Which SAS Opens Files

Files that are opened for input or update are opened from the first directory in which they are found. Files that are created or opened for output are always created in the first directory in the search list. For example, if a filename that you specify exists in both [DIR1] and [DIR3], SAS opens the file that is in [DIR1].


Example 1: Assigning a Search-String Logical Name with the X Statement

The following X statement assigns the search-string logical name MYSEARCH to the directories [DIR1], [DIR2], [DIR3], and MYLIB2:

x 'define mysearch [dir1],[dir2],[dir3],mylib2';

When you reference the data set MYSEARCH.TEST1, SAS searches [DIR1], [DIR2], [DIR3], and then the directory pointed to by MYLIB2 for the TEST1 data set:

data new;
   set mysearch.test1;
   if total>10;
run;


Example 2: Using a LIBNAME Statement

You could also use a LIBNAME statement to assign the libref INLIBS to this series of directories. You use the search-string logical name as the SAS-library specification:

libname inlibs 'mysearch';


Example 3: Specifying a Search-String Logical Name in SAS Explorer

From the SAS Explorer's New Library dialog box, you can also specify a search-string logical name to assign a libref. To do this, type the search-string logical name in the Path field.


Additional Documentation

For additional examples of how SAS files in concatenated SAS libraries are accessed, see Accessing Files in Concatenated SAS Libraries under OpenVMS.

For more information about search-string logical names, see OpenVMS User's Manual.


Concealed Logical Names

By default, SAS translates concealed logical names to their full physical specifications when they are used in LIBNAME statements. For example, consider the following definition for the logical name MYDISK:

$ DEFINE/TRANSLATION=CONCEALED -
_$ MYDISK $1$DUA100:[MYDISK.]

SAS translates the MYDISK concealed logical name to its full physical specification, resulting in the following libref definition:

1? LIBNAME MYLIB 'MYDISK:[MYDIRECTORY]';
Note: Libref MYLIB was successfully assigned
as follows:
Engine:  V9
Physical Name: $1$DUA100:[MYDISK.MYDIRECTORY]

Note:   The EXPANDLNM system option controls whether concealed logical names are expanded and displayed. Use the NOEXPANDLNM form of this option if you do not want your concealed logical names to be expanded and displayed. For more information, see EXPANDLNM System Option: OpenVMS.  [cautionend]

Previous Page | Next Page | Top of Page