Using SAS Files |
Order in Which Concatenated Directories Are Accessed |
SAS uses a set of rules to determine the order in which concatenated directories are accessed. The rules differ depending on whether you are opening a SAS file for input, update, or output:
When a SAS file is accessed for input or update, the first file found by that name is the one that is accessed. In the following example, if the data set SPECIES exists in both the [MYDIR] and [MYDIR.DATASETS] directories, the one in the [MYDIR] directory is printed:
x 'define mysearch [mydir],[mydir.datasets]'; libname mylib 'mysearch'; proc print data=mylib.species; run;
The same would be true if you used the FSEDIT procedure to open the SPECIES data set for update.
When a SAS file is accessed for output, it is always written to the first directory, if that directory exists. If the first directory does not exist, then an error message is displayed and SAS stops processing this step, even if a second directory exists. In the following example, SAS writes the SPECIES data set to the first directory, [MYDIR]:
x 'define mysearch [mydir], sas$samp:[sasdata]'; libname mylib 'mysearch'; data mylib.species; x=1; y=2; run;
If a copy of the SPECIES data set exists in the second directory, it is not replaced.
Accessing Data Sets That Have the Same Name |
If you create a new SAS data set from a data set that has the same name, the DATA statement uses the output rules and the SET statement uses the input rules. In this example, the SPECIES data set originally exists only in the second directory, MYDISK:[MYDIR].
x 'define mysearch sys$disk:[sas],mydisk:[mydir]'; libname test 'mysearch'; data test.species; set test.species; if value1='y' then value2=3; run;
The DATA statement opens SPECIES for output based on the output rules, which indicate that SAS opens a data set in the first of the concatenated directories (SYS$DISK:[SAS]).
The SET statement opens the existing SPECIES data set in the second directory(MYDISK:[MYDIR]), based on the input rules. Therefore, the original SPECIES data set is not updated. After the DATA step is processed, two SPECIES data sets exist, one in each directory.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.