Characters That Follow a
Character Constant Possible Interpretations Examples
n name literal 'My Table'n
t time constant '9:25:19pm't
x hexadecimal notation '534153'x
In the following example, '821't is evaluated as a time constant. For more information
about SAS time constants, see “Date, Time, and Datetime Constants” on page 95.
data work.europe;
set ia.europe;
if flight='821'then
flight='230';
run;
The program writes the following lines to the SAS log:
Log 6.1 Log Results from an Error Caused by a Time Literal Misinterpretation
ERROR: Invalid date/time/datetime constant '821't.
ERROR 77–185: Invalid number conversion on '821't.
ERROR 388–185: Expecting an arithmetic
operator.
Inserting a blank space between the ending quotation mark and the succeeding character
in the IF statement eliminates this misinterpretation. No error message is generated and
all observations with a FLIGHT value of 821 are replaced with a value of 230.
if flight='821' then
flight='230';
SAS Variables in Expressions
Definition
variable
is a set of data values that describe a given characteristic. A variable can be used in
an expression.
Automatic Numeric-Character Conversion
If you specify a variable in an expression, but the variable value does not match the type
called for, SAS attempts to convert the value to the expected type. SAS automatically
converts character variables to numeric variables and numeric variables to character
variables, according to the following rules:
If you use a character variable with an operator that requires numeric operands, such
as the plus sign, SAS converts the character variable to numeric.
98 Chapter 6 Expressions

Get SAS 9.4 Language Reference, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.