• If you use a comparison operator, such as the equal sign, to compare a character
variable and a numeric variable, the character variable is converted to numeric.
• If you use a numeric variable with an operator that requires a character value, such as
the concatenation operator, the numeric value is converted to character using the
BEST12. format. Because SAS stores the results of the conversion beginning with
the right-most byte, you must store the converted values in a variable of sufficient
length to accommodate the BEST12. format. You can use the LEFT function to left-
justify a result.
• If you use a numeric variable on the left side of an assignment statement and a
character variable on the right, the character variable is converted to numeric. In the
opposite situation, where the character variable is on the left and the numeric is on
the right, SAS converts the numeric variable to character using the BESTn. format,
where n is the length of the variable on the left.
When SAS performs an automatic conversion, it prints a note in the SAS log informing
you that the conversion took place. If converting a character variable to numeric
produces invalid numeric values, SAS assigns a missing value to the result, prints an
error message in the log, and sets the value of the automatic variable _ERROR_ to 1.
Note: You can also use the PUT and INPUT functions to convert data values. These
functions can be more efficient than automatic conversion. See “The Concatenation
Operator” on page 107 for an example of the PUT function. See SAS Functions and
CALL Routines: Reference for more details about these functions.
For more information about SAS variables, see Chapter 4, “SAS Variables,” on page 37.
SAS Functions in Expressions
A SAS function is a keyword that you use to perform a specific computation or system
manipulation. Functions return a value, might require one or more arguments, and can be
used in expressions. For further information about SAS functions, see SAS Functions
and CALL Routines: Reference.
SAS Operators in Expressions
Definitions
A SAS operator is a symbol that represents a comparison, arithmetic calculation, or
logical operation; a SAS function; or grouping parentheses. SAS uses two major types of
operators:
• prefix operators
• infix operators
A prefix operator is an operator that is applied to the variable, constant, function, or
parenthetic expression that immediately follows it. The plus sign (+) and minus sign (−)
can be used as prefix operators. The word NOT and its equivalent symbols are also
prefix operators. The following are examples of prefix operators used with variables,
constants, functions, and parenthetic expressions:
• +y
SAS Operators in Expressions 99