You can use the SET
system option to define a SAS environment variable. For example,
if you store your permanent SAS data sets in the C:\SAS\MYSASDATA
folder, you can use the following SET option in the SAS command when
you start SAS or in your SAS configuration file to assign the environment
variable TEST to this SAS library:
-set test c:\sas\mysasdata
When you assign an environment
variable, SAS does not resolve the environment reference until the
environment variable name is actually used. For example, if the TEST
environment variable is defined in your SAS configuration file, the
environment variable TEST is not resolved until it is referenced by
SAS. Therefore, if you make a mistake in your SET option specification,
such as misspelling a folder name, you do not receive an error message
until you use the environment variable in a SAS statement.
Because Windows filenames
can contain spaces or single quotation marks as part of their names,
you should enclose the name of the physical path in double quotation
marks when specifying the SET option. If you use the SET option in
an OPTIONS statement, you must use quotation marks around the filename.
For complete syntax of the SET system option, see SET System Option: Windows
Any environment variable
name that you use as a value for a system option in your SAS configuration
file must be defined as an environment variable before it is used.
For example, the following SET option must appear before the SASUSER
option that uses the environment variable TEST:
-set test "d:\mysasdir"
In the following example,
environment variables are used with concatenated libraries:
-set dir1 "c:\sas\base\sashelp"
-set dir2 "d:\sas\stat\sashelp"
-sashelp (!dir1 !dir2)
Note that when you reference
environment variables in your SAS configuration file or in a LIBNAME
statement in your SAS programs, you must precede the environment variable
name with an exclamation point (!).
It is recommended that
you use the SET system option in your SAS configuration file if you
invoke SAS through a Windows shortcut.