Sentry Page Protection
Variable Attributes [3-17]
Attribute #1: Variable Name
The variable name is, well, the variable name!
It is used to identify the variable in your program.
Example
Data Cars;
Set SASHelp.cars;
if enginesize > 4;
Run;
3 Restrictions on Variable Name
There is nothing complex about the variable name.
However, there are 3 restrictions on how a variable can be named.
Rule #1: Variable Name cannot exceed 32 characters
Good
- INVOICE
- MSRP
Bad
- ThisIsAVariableLongerThan32CharactersThisIsAVariableLongerThan32Characters
- Var123456789012345678901234567890
Note: although 32-character is the absolute limit for the variable name, it is generally a good programming habit to keep the variable name at no more than 8 characters.
Having a short and precise variable name is easier to type and less prone to error.
Rule #2: Variable Name cannot contain any space or special characters except underscore (_)
Good
Bad
Good
- A1234
- _GENDER_
- CAR_MODEL
Bad
- ABC%$#
- CAR MODEL
Note: underscore (_) is the only special character beside letters and numbers that can be used in a variable name.
Rule #3: Variable Name cannot start with a number
Good
Bad
Good
- A1234
- TEMP1, TEMP2, ...
Bad
- 1A
- 10TEMP
Exercise
Which of the followings are a valid variable name:
a. CUSTOMER_HOUSEHOLD_INCOME
b. MyBMW@2015
c. 2015GDP
d. ERROR
e. (a) and (d)
Which of the followings are a valid variable name:
a. CUSTOMER_HOUSEHOLD_INCOME
b. MyBMW@2015
c. 2015GDP
d. ERROR
e. (a) and (d)
Need some help?
HINT:
Carefully review which variables violated any of the 3 variable naming rules.
SOLUTION:
(e)
Fill out my online form.