multiplication1
|
|||
1The asterisk (*) is always necessary to indicate multiplication; 2Y and 2(Y) are not valid expressions. |
not equal to1
|
|||
greater than or equal
to2
|
|||
less than or equal to3
|
|||
1The symbol thatyou use for NE depends on your personal computer. | |||
2The symbol => is also accepted for compatibility with previous releases of SAS. It is not supported in WHERE clauses or in PROC SQL. | |||
3The symbol =< is also accepted for compatibility with previous releases of SAS. It is not supported in WHERE clauses or in PROC SQL. |
if x<y then c=5; else c=12;
c=5*(x<y)+12*(x>=y);Since SAS evaluates quantities inside parentheses before performing any operations, the expressions
(x<y)
and (x>=y)
are evaluated first and the result (1 or 0)
is substituted for the expressions in parentheses. Therefore, if
X=6 and Y=8, the expression evaluates as follows: c=5*(1)+12*(0)The result of this statement is C=5.
if x in (0,9,1:5);
a
,
defines a constant x
, and then uses
the IN operator to search for x
in
array a
Note that the array initialization
syntax of array a{10} (2*1:5)
creates an
array that contains the initial values of 1, 2, 3, 4, 5, 1, 2, 3,
4, 5.
G
is
greater than A
. Therefore, this expression
is true:'Gray'>'Adams'
.
is less than h
, this expression is true:'C. Jones'<'Charles Jones'
'fox '
is equivalent
to 'fox'
. However, because blanks at the
beginning and in the middle of a character value are significant to
SAS, ' fox'
is not equivalent to 'fox'
.
S
: if lastname=:'S';
S
:
OR1
|
||
NOT2
|
||
1The symbol that you use for OR depends on your operating environment. | ||
2The symbol that you use for NOT depends on your operating environment. |
a<b& c>0the result is true (has a value of 1) only when both A<B and C>0 are 1 (true): that is, when A is less than B and C is positive.
a<b|c>0The result is true (with a value of 1) when A<B is 1 (true) regardless of the value of C. It is also true when the value of C>0 is 1 (true), regardless of the values of A and B. Therefore, it is true when either or both of those relationships hold.
if x=1 or 2;SAS first evaluates X=1, and the result can be either true or false. However, since the 2 is evaluated as nonzero and nonmissing (true), the entire expression is true. In this statement, however, the condition is not necessarily true because either comparison can evaluate as true or false:
if x=1 or x=2;
0 | . = False 1 = True
if cost then remarks='Ready to budget';This statement is equivalent to:
if cost ne . and cost ne 0 then remarks='Ready to budget';A numeric expression can be simply a numeric constant, as follows:
if 5 then do;The numeric value that is returned by a function is also a valid numeric expression:
if index(address,'Avenue') then do;
level='grade
'||'A'
. The length of the resulting variable is the sum
of the lengths of each variable or constant in the concatenation operation,
unless you use a LENGTH or ATTRIB statement to specify a different
length for the new variable.
data namegame; length color name $8 game $12; color='black'; name='jack'; game=color||name; put game=; run;The value of GAME is
'black jack'
. To correct this problem, use the TRIM function in the concatenation
operation as follows: game=trim(color)||name;This statement produces a value of
'blackjack'
for the variable GAME. The following additional examples demonstrate
uses of the concatenation operator:
exponentiation1
|
|||||
positive prefix2
|
|||||
negative prefix3
|
|||||
logical not4
|
|||||
minimum5
|
|||||
concatenate character
values6
|
|||||
Group V7
|
left to right8
|
||||
logical or9
|
|||||
1Because Group I operators are evaluated from right to left, the expression x=2**3**4 is evaluated as x=(2**(3**4)). | |||||
2The plus (+) sign can be either a prefix or arithmetic operator. A plus sign is a prefix operation ly when it appears at the beginning of an expression or when it is immediately preceded by an open parenthesis or another operator. | |||||
3The minus (−) sign can be either a prefix or arithmetic operator. A minus sign is a prefix operator only when it appears at the beginning of an expression or when it is immediately preceded by an open parenthesis or another operator. | |||||
4Depending on the characters available on your keyboard, the symbol can be the not sign (¬), tilde (~), or caret (^). The SAS system option CHARCODE allows various other substitutions for unavailable special characters. | |||||
5For example, the SAS System evaluates -3><-3 as -(3><-3), which is equal to -(-3), which equals +3. This is because Group I operators are evaluated from right to left. | |||||
6Depending on the characters available on your keyboard, the symbol that you use as the concatenation operator can be a double vertical bar (||), broken vertical bar (¦¦), or exclamation mark (!!). | |||||
7Group V operators are comparison operators. The result of a comparison operation is 1 if the comparison is true and 0 if it is false. Missing values are the lowest in any comparison operation. The symbols =< (less than or equal to) are also allowed for compatibility with previous versions of the SAS System.When making character comparisons, you can use a colon (:) after any of the comparison operators to compare only the first character or characters of the value. SAS truncates the longer value to the length of the shorter value during the comparison. For example, if name=:'P' compares the value of the first character of NAME to the letter P. | |||||
8An exception to this rule occurs when two comparison operators surround a quantity. For example, the expression x<y<z is evaluated as (x<y) and (y<z). | |||||
9Depending on the characters available on your keyboard, the symbol that you use for the logical or can be a single vertical bar (|), broken vertical bar (¦), or exclamation mark (!). You can also use the mnemonic equivalent OR. |