Sas-operators
SAS-オペレーター
SASの演算子は、数学式、論理式、または比較式で使用される記号です。 これらのシンボルはSAS言語に組み込まれており、多くの演算子を1つの式に組み合わせて最終的な出力を得ることができます。
以下は、SASカテゴリの演算子のリストです。
- 算術演算子
- 論理演算子
- 比較演算子
- 最小/最大演算子
- 連結演算子
それぞれを1つずつ見ていきます。 演算子は、SASプログラムによって分析されているデータの一部である変数とともに常に使用されます。
算術演算子
次の表に、算術演算子の詳細を示します。 それぞれ値が 8 および 4 の2つのデータ変数 V1 および* V2 *を想定します。
Operator | Description | Example |
---|---|---|
+ | Addition | V1+V2=12 |
- | Subtraction | V1-V2=4 |
* | Multiplication | V1*V2=32 |
/ | Division | V1/V2=2 |
** | Exponentiation | V1**V2=4096 |
例
上記のコードを実行すると、次の出力が得られます。
論理演算子
次の表に、論理演算子の詳細を示します。 これらの演算子は、式の真理値を評価します。 したがって、論理演算子の結果は常に1または0です。 それぞれ値が 8 および 4 の2つのデータ変数 V1 および* V2 *を想定します。
Operator | Description | Example |
---|---|---|
& | The AND Operator. If both data values evaluate to true then the result is 1 else it is 0. | (V1>2 & V2 > 3) gives 0. |
The OR Operator. If any one of the data values evaluate to true then the result is 1 else it is 0. | ||
(V1>9 & V2 > 3) is 1. | ~ | The NOT Operator. The result of NOT operator in form of an expression whose value is FALSE or a missing value is 1 else it is 0. |
例
上記のコードを実行すると、次の出力が得られます。
比較演算子
次の表に、比較演算子の詳細を示します。 これらの演算子は変数の値を比較し、結果はTRUEの場合は1、Falseの場合は0で表される真理値です。 それぞれ値が 8 および 4 の2つのデータ変数 V1 および* V2 *を想定します。
Operator | Description | Example |
---|---|---|
= | The EQUAL Operator. If both data values are equal then the result is 1 else it is 0. | (V1 = 8) gives 1. |
^= | The NOT EQUAL Operator. If both data values are unequal then the result is 1 else it is 0. | (V1 ^= V2) gives 1. |
< | The LESS THAN Operator. | (V2 < V2) gives 1. |
⇐ | The LESS THAN or EQUAL TO Operator. | (V2 ⇐ 4) gives 1. |
> | The GREATER THAN Operator. | (V2 > V1) gives 1. |
>= | The GREATER THAN or EQUAL TO Operator. | (V2 >= V1) gives 0. |
IN | The IN Operator. If the value of the variable is equal to any one of the values in a given list of values, then it returns 1 else it returns 0. | V1 in (5,7,9,8) gives 1. |
例
上記のコードを実行すると、次の出力が得られます。
最小/最大演算子
次の表に、最小/最大演算子の詳細を示します。 これらの演算子は、行全体で変数の値を比較し、行の値のリストから最小値または最大値が返されます。
Operator | Description | Example |
---|---|---|
MIN | The MIN Operator. It returns the minimum value form the list of values in the row. | MIN(45.2,11.6,15.41) gives 11.6 |
MAX | The MAX Operator. It returns the maximum value form the list of values in the row. | MAX(45.2,11.6,15.41) gives 45.2 |
例
上記のコードを実行すると、次の出力が得られます。
連結演算子
次の表に、連結演算子の詳細を示します。 この演算子は、2つ以上の文字列値を連結します。 単一の文字値が返されます。
Operator | Description | Example |
---|---|---|
The concatenate Operator. It returns the concatenation of two or more values. | 'Hello' |
例
上記のコードを実行すると、次の出力が得られます。
演算子の優先順位
演算子の優先順位は、複雑な式に存在する複数の演算子の評価の順序を示します。 次の表は、演算子のグループでの優先順位を示しています。
Group | Order | Symbols |
---|---|---|
Group I | Right to Left | ** + - NOT MIN MAX |
Group II | Left to Right | */ |
Group III | Left to Right | + - |
Group IV | Left to Right | |
Group V |