Operators for Calculated Data Items

Overview of Operators for Calculated Data Items

In SAS Visual Analytics Explorer and SAS Visual Analytics Designer, you can calculate data items by using expressions that contain operators. The operators that you can use are grouped into the following categories:
Numeric (simple) operators
perform basic mathematical operations such as addition and multiplication. See Numeric (Simple) Operators.
Numeric (advanced) operators
perform advanced mathematical functions such as evaluating logarithms and truncating decimals. See Numeric (Advanced) Operators.
Boolean operators
evaluate whether a set of logical conditions is true. See Boolean Operators.
Comparison operators
evaluate how the values of your data items compare. See Comparison Operators.
Date and Time operators
convert values to, from, or between date and time formats. See Date and Time Operators.

Numeric (Simple) Operators

-x (Negation)
returns a value with the opposite sign of the input value.
For example, -1 returns 1 and 1 returns -1.
x - y (Minus)
subtracts the second value from the first value.
For example, (2,1) returns 1.
x * y (Multiply)
multiplies the first and second values together.
For example, (2,3) returns 6.
x / y (Divide)
divides the first value by the second value.
For example, (6,2) returns 3.
x + y (Plus)
adds the first and second values together.
For example, (1,2) returns 3.

Numeric (Advanced) Operators

|x| (Absolute value)
returns the absolute value of the input value.
For example, -3 returns 3.
Ceil (Ceiling)
rounds the input value up to the nearest integer.
For example, 4.2 returns 5 and -4.8 returns -4.
Exp (e**exponent)
raises the constant e to the power specified by the input value.
For example, 5 returns e to the 5th power (148.41).
Floor (Floor)
rounds the input value down to the nearest integer.
For example, 4.8 returns 4 and -4.2 returns -5.
Ln (Natural log)
returns the natural logarithm (base e) of the input value.
For example, 10 returns the eth root of 10 (2.30...).
Log (Log)
returns the logarithm of the first value, where the second value specifies the base.
For example, (64, 8) returns the base 8 logarithm of 64 (2).
Mod (Remainder)
returns the remainder after dividing the first value by the second value.
For example, (5,2) returns 1.
Power (Base**Exponent)
raises the first value to the power of the second value.
For example, (5,2) returns 5 to the 2nd power (25).
Root (Root of an Expression)
returns the nth root of the first value, where the second value specifies n (the base of the root).
For example, (27,3) returns the 3rd (cube) root of 27 (3).
Round (Round the Number)
round the first value to the number of decimal places that is specified by the second value. Select the second value from the drop-down list.
For example, (7.354, 2) returns 7.35.
Note: If you select 0 decimal places, then the values are rounded to the nearest integer.
Trunc (Truncate to Whole Number)
truncates the input value to an integer.
For example, 8.9 returns 8 and -8.9 returns -8.

Boolean Operators

And (Logical And)
joins two conditions and returns true if both conditions are true.
For example,
(1 = 1) AND (2 = 2)
returns true, and
(1 = 1) AND (2 = 1)
returns false.
If... Else (Conditional Return Value)
returns different values, depending on whether the condition is true. The first parameter specifies the condition. The second parameter specifies the value to return if the condition is true. The third parameter specifies the value to return if the condition is false.
For example,
if (X > Y) return X else Y
returns the value of X if X is greater than Y, but returns the value of Y otherwise.
Not
returns true if the condition is false.
For example, not (1 = 2)returns true.
Or (Logical Or)
joins two conditions and returns true if either condition is true.
For example,
(1 = 1) OR (2 = 2)
returns true, and
(1 = 1) OR (2 = 1)
returns true.

Comparison Operators

Between (Number in Range)
returns true if the first value is between the second and third values (inclusive.)
For example, (X, 50, 100) returns true if X is between 50 and 100.
In List
returns true if the first value is in the list specified by the second parameter. To select your list, assign a data item to the first parameter and then choose the values from the drop-down list.
For example, X In (1,2,3) returns true when the value of X is either 1, 2, or 3.
Note: This operator cannot be used to compare measures.
Note: This operator is available only in SAS Visual Analytics Explorer.
Missing (Is Missing Value)
returns true if the value is a missing value.
Not in List
returns true if the first value is not in the list specified by the second parameter. To select your list, assign a data item to the first parameter and then choose the values from the drop-down list.
For example, X NotIn (1,2,3) returns true when the value of X is not 1, 2, or 3.
Note: This operator cannot be used to compare measures.
Note: This operator is available only in SAS Visual Analytics Explorer.
NotMissing (Is not Missing Value)
returns true if the value is not a missing value.
Note: This operator is available only in SAS Visual Analytics Explorer.
x != y (Not Equal)
returns true if the first value is not equal to the second value.
Note: This operator cannot be used to compare measures.
x < y (Less Than)
returns true if the first value is less than the second value.
x <= y (Less Than or Equal)
returns true if the first value is less than or equal to the second value.
Note: This operator cannot be used to compare measures.
x = y (Equal)
returns true if the first value is equal to the second value.
Note: This operator cannot be used to compare measures.
x > y (Greater Than)
returns true if the first value is greater than the second value.
x >= (Greater Than or Equal)
returns true if the first value is greater than or equal to the second value.
Note: This operator cannot be used to compare measures.

Date and Time Operators

DateFromMDY
creates a date value from separate month, day, and year values. The first value specifies the month as a number between 1–12. The second value specifies the day as a number between 1–31. The third value specifies the year as a four-digit number.
For example, (1,15,2013) returns 15JAN2013.
DateFromYQ
creates a date value from separate year and quarter values. The first value specifies the year as a four-digit number. The second value specifies the quarter as a number between 1–4.
For example, (2013,1) returns 01JAN2013.
Note: The date is generated using the first day of each quarter.
DatePart
converts a datetime value to a date value.
For example, January 15, 2013 05:15 PM returns 15JAN2013.
DateTimeFromDateHMS
creates a datetime value from a date value and separate hour, minute, and second values. The first value specifies the date. The second value specifies the hour as a number between 0–23. The third value specifies the minute as a number between 0–59. The fourth value specifies the second as a number between 0–59.
For example, (15JAN2013, 17, 15, 23) returns January 15, 2013 05:15:23 PM
DateTimeFromTimeMDY
creates a datetime value from a time value and separate month, day, and year values. The first value specifies the time. The second value specifies the month as a number between 1–12. The third value specifies the day as a number between 1–31. The fourth value specifies the year as a four-digit number.
For example, (05:15:23 PM, 1, 15, 2013) returns January 15, 2013 05:15:23 PM.
DayOfMonth
returns the day of the month from a date value as a number between 1–31.
For example, 15JAN2013 returns 15.
DayOfWeek
returns the day of the week from a date value as a number between 1–7 (1 is Sunday.)
For example, 15JAN2013 returns 3 (Tuesday.)
DayOfYear
returns the day of the year from a date value as a number between 1–366.
For example, 15FEB2013 returns 46.
Hour
returns the hour from a time or datetime value as a number between 0–23.
For example, 05:15:23 PM returns 17.
Minute
returns the minute from a time or datetime value as a number between 0–59.
For example, 05:15:23 PM returns 15.
Month
returns the month from a date value as a number between 1–12.
For example, 15JAN2013 returns 1.
Now
creates a datetime value from the current date and time.
Quarter
returns the quarter from a date value as a number between 1–4.
For example, 15AUG2013 returns 3.
Second
returns the second from a time or datetime value as a number between 0–59.
For example, 05:15:23 PM returns 23.
TimeFromHMS
creates a time value from separate hour, minute, and second values. The first value specifies the hour as a number between 0–23. The second value specifies the minute as a number between 0–59. The third value specifies the second as a number between 0–59.
For example, (17,15,23) returns 05:15:23 PM.
TimePart
converts a datetime value to a time value.
For example, January 15, 2013 05:15:23 PM returns 05:15:23 PM.
WeekNumber
returns the week of the year as a number between 1–53, where week 2 begins on the second Sunday of the year.
For example, 04AUG2013 returns 31.
Year
returns the year from a date value as a four-digit number.
For example, 15JAN2013 returns 2013.