SAS Component Language: Reference |
In
SCL, a constant (or literal) is a fixed value that can be either a number
or a character string. Constants can be used in many SCL statements, including
assignment and IF-THEN statements. They can also be used as values for certain
options.
A numeric constant
is a number that appears in a SAS statement, and it can be presented in the
following forms:
- standard syntax, in which numeric constants are
expressed as integers, can be specified with or without a plus or minus sign,
and can include decimal places.
- scientific (E) syntax, in which the number that
precedes the E is multiplied by the power of ten indicated by the number that
follows the E.
- hexadecimal syntax, in which a numeric hex constant
starts with a numeric digit (usually 0), can be followed by more hexadecimal
digits, and ends with the letter X. The constant can contain up to 16 hexadecimal
digits (0 to 9, A to F).
- special SAS date and time values, in which the
date or time is enclosed in single or double quotation marks, followed by
a D (date), T (time), or DT (datetime) to indicate the type of value (for
example, '15jan99'd).
A character constant can consist of 1 to 32,767 characters and must be enclosed
in quotation marks. Character constants can be represented in the following
forms:
- hexadecimal form, in which a string of an even
number of hex characters is enclosed in single or double quotation marks,
followed immediately by an X, as in this example:
'534153'x
- bit form, in which a string of 0s, 1s, and periods
is surrounded by quotation marks and is immediately followed by a B. Zero
tests whether a bit is off, 1 tests whether a bit is on, and a period ignores
a bit. Commas and blanks can be inserted in the bit mask for readability without
affecting its meaning.
In the following example, if the third bit of A (counting
from the left) is on, and the fifth through eighth bits are off, then the
comparison is true and the expression results in 1. Otherwise, the comparison
is false and the expression results in 0.
if a='..1.0000'b then do;
Bit constants cannot be used as literals in assignment statements.
For example, the following statement is not valid:
x='0101'b; /* incorrect */
If a character constant includes a single quotation
mark, then either write the quotation mark as two consecutive single quotation
marks or surround the entire value with double quotation marks, as shown in
the following examples:
possession='Your"s';
company="Your's and Mine"
company="Your""s and Mine"
To use a null character value as an argument to a function in SCL,
either use
''
(without
a space) or use a blank value with
' '
(with a space).
|
Numeric-to-Character Conversion |
If a value is
inconsistent with the variable's data type, SCL
attempts to convert the value to the expected type. SCL automatically converts
character variables to numeric variables and numeric variables to character
variables, according to the following rules:
- A character variable is converted to numeric when
the character variable is used
- with an operator that requires numeric operands
(for example, the plus sign)
- with a comparison operator (for example, the equal
sign) to compare a character variable and a numeric variable
- on the right side of an assignment statement,
when a numeric variable is on the left side.
- A numeric variable is converted to character when
the numeric variable is used
- with an operator that requires a character value
(for example, the concatenation operator)
- on the right side of an assignment statement,
when a character variable is on the left side.
When a variable is converted automatically, a message
in the LOG window warns you that the conversion
took place. If a conversion from character to numeric produces invalid numeric
values, then a missing value is assigned to the result, an error message appears
in the LOG window, and the value of the automatic
variable _ERROR_ is set to 1.
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.