Getting Started with SAS in UNIX Environments |
What Is a UNIX Environment Variable? |
UNIX environment variables are variables that apply to both the current shell and to any subshells it creates (for example, when you send a job to the background or execute a script). If you change the value of an environment variable, the change is passed forward to subsequent shells but not backward to the parent shell.
In a SAS session, you can use the SASV9_OPTIONS environment variable to specify system options and the SASV9_CONFIG environment variable to specify a configuration file. You can also use environment variables as filerefs and librefs in various statements and commands. Filerefs and librefs consist of uppercase letters, digits, and the underscore character in environment variable names. Other characters are not recognized by SAS.
Note: A SAS/ACCESS product initializes the environment variables it needs when loading. Any changes that you make to an environment variable after initialization will not be recognized. For more information, see the documentation for your SAS/ACCESS product.
How to Define an Environment Variable for Your Shell |
The way in which you define an environment variable depends on the shell that you are running. (To determine which shell you are running, type ps at the command prompt or echo $SHELL to see the current value of the SHELL environment variable.)
In the Bourne shell and in the Korn shell, use the export command to export one or more variables to the environment. For example, these commands make the value of the variable scname available to all subsequent shell scripts:
$ scname=phonelist $ export scname
In the Korn shell, you can combine these commands into one command:
$ export scname=phonelist
If you change the value of scname , then the new value affects both the shell variable and the environment variable. If you do not export a variable, only the shell script in which you define has access to its value.
In the C shell (csh and tcsh), you set (define and export) environment variables with the setenv (set environment) command. For example, this command is equivalent to the commands shown previously:
% setenv scname phonelist
Displaying the Value of an Environment Variable |
To display the values of individual environment variables, use the echo command and parameter substitution. An example is: echo $SHELL which returns the current value of the SHELL environment variable. Use the env (or printenv ) command to display all environment variables and their current values.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.