Whether you specify a data file name directly in the various SAS statements or specify the data library
Specify directory and file pathnames in quotation marks. The level of specification depends on your current directory.
If
/u/1999/
data '/u/1999/budgets/may';
If you wanted to use a libref, you would specify:
libname budgets '/u/1999/budgets'; data budgets.may;
If
/u/1999/budgets
is your current directory, you could specify only the data file
data 'quarter1'; merge 'jan' 'feb' 'mar'; run;
| Note |
If you omit the quotation marks, then SAS assumes that these data sets are stored in the Saswork directory. |
If you wanted to use a libref, you would specify:
libname budgets '.'; data budgets.quarter1; merge budgets.jan budgets.feb budgets.mar; run;
You can use the character substitutions shown in the following table to specify pathnames.
|
Characters |
Meaning |
|---|---|
|
~/ |
$HOME/ Can be used only at the beginning of a pathname. |
|
~ name / |
name 's home directory (taken from file /etc/passwd ). Can be used only at the beginning of a pathname. |
|
!
|
name of sasroot directory (see Appendix 1, "The !SASROOT Directory," on page 397). Specified only at the beginning of a pathname. |
|
. |
current working directory |
|
.. |
parent of current working directory |
|
$ VARIABLE |
environment variable VARIABLE |
You can use the LIBNAME statement to assign librefs and engines to one or more directories, including the Work directory.
If you have SAS data sets located in multiple directories, you can treat these directories as a single SAS data library by specifying a single libref and concatenating the directory locations, as in the following example:
libname income ('/u/2002/revenue', '/u/2002/costs');
This statement indicates that the two directories, /u/2002/revenue and /u/2002/costs , are to be treated as a single SAS data library.
If you have already assigned librefs to your SAS data libraries, you can use these librefs to
libname income ('/u/2002/corpsale', '/u/2002/retail');
libname costs ('/u/2002/salaries', '/u/2002/expenses');
libname profits (income, costs, '/u/2002/capgain');
This statement indicates that the five directories, /u/2002/corpsale , /u/2002/retail , /u/2002/salaries , /u/2002/expenses , and /u/2002/capgain , are to be treated as a single SAS data library.
When you concatenate SAS data libraries, SAS uses a protocol for accessing the libraries, which depends on whether you are accessing the libraries for read, write, or update. (A protocol is a set of rules.)
SAS uses the protocol shown in the following sections to determine which directory is accessed. (The protocol
When a SAS data set is accessed for input or update, the first SAS data set that is found by that
libname old ('mysasdir','saslib');
proc print data=old.species;
run;
The same would be true if you opened Old.Species for update with the FSEDIT procedure.
If the data set is accessed for output, it is always written to the first directory, provided that the directory exists. If the directory does not exist, an error message is displayed. For example, if you submit the following statements, SAS
libname old ('mysasdir','saslib');
data old.species;
x=1;
y=2;
run;
If a copy of the Old.Species data set exists in the second directory, it is not
If you use the DATA and SET statements to access data sets with the same name, the DATA statement uses the output rules and the SET statement uses the input rules. For example, suppose you submit the following statements and Test.Species originally exists only in the second directory, mysasdir :
libname test ('sas','mysasdir');
data test.species;
set test.species;
if value1='y' then
value2=3;
run;
The DATA statement opens Test.Species for output according to the output rules; that is, SAS opens a data set in the first of the concatenated libraries ( sas ). The SET statement opens the existing Test.Species data set in the second ( mysasdir ) directory, according to the input rules. Therefore, the original Test.Species data set is not updated. After the data step executes, two Test.Species data sets exist, one in each directory.