Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
UNC-Wilmington Department of Economics and Finance ECN 377 Dr. Chris Dumas Mathematical and Logical Operators in SAS (TIP: For more info, when in SAS go to SAS Help, click on Index tab, and search using keywords “Expressions” and “Functions”.) A SAS operator is a symbol that represents a comparison, arithmetic calculation, or logical operation; a SAS function; or grouping parentheses. Arithmetic Operators Symbol Definition Example ** exponentiation a**3 * multiplication 2*y Result raise A to the third power multiply 2 by the value of Y / division var/5 divide the value of VAR by 5 + addition num+3 add 3 to the value of NUM - subtraction sale-discount subtract the value of DISCOUNT from the value of SALE NOTE 1: The asterisk (*) is always necessary to indicate multiplication; 2Y and 2(Y) are not valid expressions. NOTE 2: If a missing value is an operand for an arithmetic operator, the result is a missing value. So, if you tell SAS to calculate y = a*X, and either “a” or “X” is a missing value, then “y” will be a missing value. The LOG and LOG10 Operators The operator “LOG” performs natural logarithms, and the operator “LOG10” performs base 10 logarithms. For example, lnGNP = LOG(GNP); creates a new variable named lnGNP by taking the natural log of variable GNP. 1 Comparison Operators Symbol Mnemonic Equivalent Definition Example = EQ equal to a=3 a EQ 3 ^= NE not equal to a ^= 3 a NE 3 ¬= NE not equal to a ¬= 3 ~= NE not equal to a ~= 3 > GT greater than a>5 < LT less than a<8 >= GE greater than or equal to a>=300 <= LE less than or equal to (no symbol for this one) IN equal to one of the items in a list a<=100 A LE 100 a IN (3, 4, 5) NOTE: You can use either the math symbols or the mnemonic equivalents (or both) when writing equations in SAS. NOTE: Comparison operators appear frequently in IF-THEN statements, as in this example: if x<y then c=5; if x LT y then c EQ 5; 2 Logical Operators Logical operators, also called Boolean operators, are usually used in expressions to link sequences of comparisons. The logical operators are shown in the following table: Symbol Mnemonic Equivalent Example & AND (a>b & c>d) | OR (a>b or c>d) ! OR ¦ OR ¬ NOT ˆ NOT ~ NOT not(a>b) NOTE: Notice in the table above that there are several, alternative symbols that you could use for “OR” or “NOT.” The symbol that you should use for OR or NOT depends on your “operating environment” (the particular keyboard and operating system software that you are using). The MIN and MAX Operators The MIN and MAX operators are used to find the minimum or maximum value of two quantities. MIN >< MAX <> MIN operator Surround the operators with the two quantities whose minimum or maximum value you want to know. The MIN operator, " >< ", returns the lower of the two values. The MAX operator, " <> ", operator returns the higher of the two values. For example, the command “y = a><b;” would set y equal to the smaller of a or b. 3