Rules for SAS Variable Names

The rules for SAS variable names have expanded to provide more functionality. The setting of the VALIDVARNAME= system option determines what rules apply to the variables that you can create and process in your SAS session as well as to variables that you want to read from existing data sets. The VALIDVARNAME= option has three settings (V7, UPCASE, and ANY), each with varying degrees of flexibility for variable names.

V7. V7 is the default setting.

Variable name rules are as follows:

  1. SAS variable names can be up to 32 characters in length.

  2. The first character must begin with an English letter or an underscore. Subsequent characters can be English letters, numeric digits, or underscores.

  3. A variable name cannot contain spaces.

  4. A variable name cannot contain any special characters other than the underscore.

  5. A variable name can contain mixed case. Mixed case is remembered and used for presentation purposes only. (SAS stores the case used in the first reference to a variable.) When SAS processes variable names, however, it internally uppercases them. You cannot, therefore, use the same letters with different combinations of lowercase and uppercase to represent different variables. For example, cat, Cat, and CAT all represent the same variable.

  6. Do not assign the names of special SAS automatic variables (such as _N_ and _ERROR_) or variable list names (such as _NUMERIC_, _CHARACTER_, and _ALL_) to variables.

  7. Keywords to avoid for variable names are: AND, BY, EQ, GE, GT, LE, LT, NE, NOT, OR, TO, WITH, and ADD.

UPCASE. UPCASE is the same as V7 except that variable names are upper-cased, as in earlier versions of SAS.

ANY.

  1. SAS variable names can be up to 32 characters in length.

  2. The name can start with or contain any characters, including spaces.

CAUTION:

Available for Base SAS procedures and SAS/STAT procedures only.

VALIDVARNAME=ANY has been verified for use with only Base SAS procedures and SAS/STAT procedures. Any other use of this option is considered experimental and might cause undetected errors.   

Note: If you use any characters other than English letters, numeric digits, or underscores, you must express the variable name as a name literal and you must set VALIDVARNAME=ANY. If you use either the percent sign (%) or the ampersand (&), you must use single quotation marks in the name literal in order to avoid interaction with the SAS Macro Facility.  

3.  A variable name can contain mixed case. Mixed case is stored and used for presentation purposes only. (SAS stores the case that is used in the first reference to a variable.) When SAS processes variable names, however, it internally uppercases them. Therefore, you cannot use the same letters with different combinations of lowercase and uppercase to represent different variables. For example, cat, Cat, and CAT all represent the same variable.

4. STATISTICA will deploy all text values of categorical variables as-is into the SAS deployment script. In order to ensure proper deployment, verify that the text values of categorical variables found in your subsequent SAS data files match those found in the SAS deployment script.

Note: The dialog and/or warning message described below may be displayed when using the deployment to SAS option:

Code Generator. A general message that alerts STATISTICA-generated SAS deployment code users of the variable naming conventions of SAS.

Don't show this dialog again. Select this check box to prohibit this dialog from being shown again.

Close. Click this button to close this dialog.

STATISTICA. This warning message is displayed before producing the SAS code if there are variables names that do not follow the Rules for SAS Variable Names (see above) in the STATISTICA input file. The user must change such names before deploying the code in SAS.

See also, Example: SAS Deployment.