Search the site...

SASCRUNCH TRAINING
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
  • Home
  • Member's Area
  • How to Start
  • SAS Interface
  • Creating a Data Set
  • Practical SAS Training Course
  • SAS Certified Specialist Training Program
  • Proc SQL Course
  • Introduction to Time Series Analysis
  • SAS Project Training Course
  • Full Training / Membership
  • Sign up
  • About us
  • Contact us
Sentry Page Protection
Please Wait...
Variable Attributes [3-17]


Attribute #1: Variable Name
Picture

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;
Picture

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.
Picture


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
  • 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
  • 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)
Next

Need some help? 


HINT:
Carefully review which variables violated any of the 3 variable naming rules.


SOLUTION:
(e)


Fill out my online form.

Already a member? Go to member's area.