Specifying Pathnames in UNIX Environments


Rules for Specifying Pathnames

You can reference an external file directly by specifying its pathname in the FILE, INFILE, or %INCLUDE statements, or you can reference the file indirectly by specifying a fileref and a pathname in the FILENAME statement and then using the fileref in the FILE, INFILE, or %INCLUDE statements.

Whether you reference a file directly or indirectly, you will need to specify its pathname in the appropriate statement. In most cases, you must enclose the name in quotation marks. For example, the following INFILE statement refers to the file /users/pat/ cars :

 infile '/users/pat/cars'; 

The following FILE statement directs output to the specified terminal:

 file '/dev/ttyp1'; 

The level of specification depends on your current directory. You can use the character substitutions shown in Table 4.6 on page 115 to specify the pathname. You can also use wildcards as described in "Using Wildcards in Pathnames (Input Only)" on page 134.

Exceptions to Enclosing the Filename in Quotation Marks

You can omit the quotation marks on a filename if

  • there is not already a fileref defined with that filename.

  • the file has the filename extension expected by the statement that you are using to refer to the file. If you do not enclose a filename in quotation marks, the FILE and INFILE statements assume a file extension of .dat, and the %INCLUDE statement assumes a file extension of .sas.

  • the file is in the current directory.

  • the filename is all lower case characters .

For example, if the current directory is /users/mkt/report and it includes file Qtr.sas, you can reference Qtr.sas in any of the following statements:

 %include '/users/mkt/report/qtr.sas';   %include 'qtr.sas';   file 'qtr.sas'; 

If there is no Qtr fileref already defined, you can omit the quotation marks and the filename extension on the %INCLUDE statement:

 %include qtr; 

Using Wildcards in Pathnames (Input Only)

Descriptions of the Valid Wildcards

You can use the *, ?, and [ ]wildcards to specify pathnames in the FILENAME (only if the fileref is to be used for input), INFILE, and %INCLUDE statements and the INCLUDE command.

*

matches one or more characters, except for the period at the

beginning of filenames.

?

matches any single character.

[ ]

matches any single character from the set of characters defined within the brackets. You can specify a range of characters by specifying the starting character and ending character separated by a hyphen.

Wildcards are supported for input only. You cannot use wildcards in the FILE statement.

Example 1: Selecting Files by Including a Wildcard in a String

The following example reads input from every file in the current directory that begins with the string wild and ends with .dat:

 filename wild 'wild*.dat';   data;      infile wild;      input;   run; 

Example 2: Reading Each File in the Current Directory

The following example reads input from every file in every subdirectory of the current working directory:

 filename subfiles '*/*';   data;      infile subfiles;      input;   run; 

If new files are added to any of the subdirectories, they can be accessed with the Subfiles fileref without changing the FILENAME statement.

Example 3: Wildcards in Filenames When using Aggregate Syntax

You can also use wildcards in filenames, but not in directory names , when you use aggregate syntax:

 filename curdir ".";   data;     infile curdir('wild*');     input;   run; 

In the example above, the period in the FILENAME statement refers to the current directory. See Table 4.6 on page 115 for information about other character substitutions available on UNIX.

Example 4: Associating a Fileref with Multiple Files

The following statement associates the fileref MyRef with all files that begin with alphabetic characters. Files beginning with numbers or other characters such as the period or tilde are excluded.

 filename myref  '[a-zA-Z]*.dat'; 

The following statement associates MyRef with any file beginning with Sales (in either uppercase, lowercase, or mixed case) and a year between 1990 and 1999:

 filename myref  '[Ss][Aa][Ll][Ee][Ss]199[0-9].dat'; 



SAS 9.1 Companion for UNIX Environments
SAS 9.1 Companion For Unix Enivronments
ISBN: 1590472101
EAN: 2147483647
Year: 2004
Pages: 185
Authors: SAS Institute

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net