To illustrate how
the macro processor evaluates logical expressions, consider the COMPCHAR
macro. Invoking the COMPCHAR macro compares the values passed as
parameters and places the result in the log.
%macro compchar(first,second);
%if &first>&second %then %put &first comes after &second;
%else %put &first comes before &second;
%mend compchar;
Invoke the macro COMPCHAR
with these values:
%compchar(a,b)
%compchar(.,1)
%compchar(Z,E)
The following results
are printed in the log:
a comes before b
. comes before 1
Z comes after E
When the macro processor
evaluates expressions with character operands, it uses the sort sequence
of the host operating system for the comparison. The comparisons
in these examples work with both EBCDIC and ASCII sort sequences.
A special case of a
character operand is an operand that looks numeric but contains a
period character. If you use an operand with a period character in
an expression, both operands are compared as character values. This
can lead to unexpected results. So that you can understand and better
anticipate results, look at the following examples.
Invoke the COMPNUM macro
with these values:
The following values
are written to the log:
Because the %IF-THEN
statement in the COMPNUM macro uses integer evaluation, it does not
convert the operands with decimal points to numeric values. The operands
are compared as character strings using the host sort sequence, which
is the comparison of characters with smallest-to-largest values. For
example, lowercase letters might have smaller values than uppercase,
and uppercase letters might have smaller values than digits.
CAUTION:
The host
sort sequence determines comparison results.
If you use a macro
definition on more than one operating system, comparison results might
differ because the sort sequence of one host operating system might
differ from the other system. See the
SORT Procedure in Base SAS Procedures Guide for more information about host sort
sequences.