Using External Files |
To establish the communication between SAS software and an external file, you must assign a fileref to the file with the FILENAME function. If an application requires that users specify the name of the physical file, then create a block of SCL code labeled with a window variable name to run only when a user enters a filename in that field. You can also put the FILENAME function in the MAIN section so that it executes after a user specifies the filename. In this case, add a statement to check that the field containing the filename has been modified so that the FILENAME function does not run every time the MAIN section runs. When a program can specify the name of the physical file without user input, put the function in the initialization section so that the function executes only once, before the window opens.
You can also assign filerefs outside of an application when files are used by all or large parts of your application. You assign filerefs to these files by using the FILENAME statement in Base SAS in the application's start-up file (the autoexec file). For more information about assigning filerefs, see the SAS documentation for your operating environment.
There are other SCL functions that you can use to manipulate filerefs. Use these functions to prevent programs from terminating prematurely because of possible errors (for example, a fileref is already assigned or a physical file does not exist).
Use the FILEREF function to verify that a fileref has been assigned to a physical file for the current SAS session or process.
Use the FEXIST function to verify that the file associated with a specified fileref exists.
Use the FILEEXIST function to verify that the file associated with a physical name exists.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.