Characters (usually shown asCHAR) are typically used within a CLEM expression to perform tests on strings. For example, you can use the functionisuppercodeto determine whether thefirst character of a string is upper case. The following CLEM expression uses a character to indicate that the test should be performed on thefirst character of the string:
isuppercode(subscrs(1, "MyString"))
To express the code (in contrast to the location) of a particular character in a CLEM expression, use single backquotes of the form`<character>`––for example,`A`,`Z`.
Note: There is noCHARstorage type for afield, so if afield is derived orfilled with an expression that results in aCHAR, then that result will be converted to a string.
129 CLEM Language Reference
Strings
Generally, you should enclose strings in double quotation marks. Examples of strings are "c35product2"and"referrerID". To indicate special characters in a string, use a backslash––for example,"\$65443". (To indicate a backslash character, use a double backslash,\\.) You can use single quotes around a string, but the result is indistinguishable from a quotedfield ('referrerID'). For more information, see the topicString Functionson p. 141.
Lists
A list is an ordered sequence of elements, which may be of mixed type. Lists are enclosed in square brackets ([]). Examples of lists are[1 2 4 16]and["abc" "def"]. Lists are not used as the value of IBM® SPSS® Modelerfields. They are used to provide arguments to functions, such as memberandoneof.
Fields
Names in CLEM expressions that are not names of functions are assumed to befield names. You can write these simply asPower,val27,state_flag, and so on, but if the name begins with a digit or includes non-alphabetic characters, such as spaces (with the exception of the underscore), place the name within single quotation marks––for example,'Power Increase','2nd answer','#101', '$P-NextField'.
Note: Fields that are quoted but undefined in the data set will be misread as strings.
Dates
Date calculations are based on a “baseline” date, which is specified in the stream properties dialog box. The default baseline date is 1 January 1900. For more information, see the topicSetting general options for streamsin Chapter 5 on p. 55.
The CLEM language supports the following date formats.
Format Examples
DDMMYY 150163
MMDDYY 011563
YYMMDD 630115
YYYYMMDD 19630115
YYYYDDD Four-digit year followed by a three-digit number representing the day of the year—for example,2000032represents the 32nd day of 2000, or 1 February 2000.
DAY Day of the week in the current locale—for example,Monday,Tuesday, ..., in English.
MONTH Month in the current locale—for example,January,February, ….
Format Examples DD/MM/YYYY 15/01/1963 MM/DD/YY 01/15/63 MM/DD/YYYY 01/15/1963 DD-MM-YY 15-01-63 DD-MM-YYYY 15-01-1963 MM-DD-YY 01-15-63 MM-DD-YYYY 01-15-1963 DD.MM.YY 15.01.63 DD.MM.YYYY 15.01.1963 MM.DD.YY 01.15.63 MM.DD.YYYY 01.15.1963
DD-MON-YY 15-JAN-63, 15-jan-63, 15-Jan-63 DD/MON/YY 15/JAN/63, 15/jan/63, 15/Jan/63 DD.MON.YY 15.JAN.63, 15.jan.63, 15.Jan.63 DD-MON-YYYY 15-JAN-1963, 15-jan-1963, 15-Jan-1963 DD/MON/YYYY 15/JAN/1963, 15/jan/1963, 15/Jan/1963 DD.MON.YYYY 15.JAN.1963, 15.jan.1963, 15.Jan.1963 MON YYYY Jan 2004
q Q YYYY Date represented as a digit (1–4) representing the quarter followed by the letterQand a four-digit year—for example, 25 December 2004 would be represented as4 Q 2004.
ww WK YYYY Two-digit number representing the week of the year followed by the lettersWK and then a four-digit year. The week of the year is calculated assuming that the
first day of the week is Monday and there is at least one day in thefirst week.
Time
The CLEM language supports the following time formats.
Format Examples HHMMSS 120112, 010101, 221212 HHMM 1223, 0745, 2207 MMSS 5558, 0100 HH:MM:SS 12:01:12, 01:01:01, 22:12:12 HH:MM 12:23, 07:45, 22:07 MM:SS 55:58, 01:00 (H)H:(M)M:(S)S 12:1:12, 1:1:1, 22:12:12 (H)H:(M)M 12:23, 7:45, 22:7 (M)M:(S)S 55:58, 1:0 HH.MM.SS 12.01.12, 01.01.01, 22.12.12 HH.MM 12.23, 07.45, 22.07
131 CLEM Language Reference
Format Examples MM.SS 55.58, 01.00 (H)H.(M)M.(S)S 12.1.12, 1.1.1, 22.12.12 (H)H.(M)M 12.23, 7.45, 22.7 (M)M.(S)S 55.58, 1.0
CLEM Operators
The following operators are available.
Operation Comments Precedence (see next section)
or Used between two CLEM expressions. Returns a value of true if either is true or if both are true.
10
and Used between two CLEM expressions. Returns a value of true if both are true.
9
= Used between any two comparable items. Returns true if ITEM1 is equal to ITEM2.
7
== Identical to=. 7
/= Used between any two comparable items. Returns true if ITEM1 isnot equal to ITEM2.
7
/== Identical to/=. 7
> Used between any two comparable items. Returns true if ITEM1 is strictly greater than ITEM2.
6
>= Used between any two comparable items. Returns true if ITEM1 is greater than or equal to ITEM2.
6
< Used between any two comparable items. Returns true if ITEM1 is strictly less than ITEM2
6
<= Used between any two comparable items. Returns true if ITEM1 is less than or equal to ITEM2.
6
&&=_0 Used between two integers. Equivalent to the Boolean expression INT1 && INT2 = 0.
6
&&/=_0 Used between two integers. Equivalent to the Boolean expression INT1 && INT2 /= 0.
6
+ Adds two numbers: NUM1 + NUM2. 5
>< Concatenates two strings; for example, STRING1 >< STRING2.
5
- Subtracts one number from another: NUM1 - NUM2. Can also be used in front of a number: - NUM.
5
* Used to multiply two numbers: NUM1 * NUM2.
Operation Comments Precedence (see next section)
&& Used between two integers. The result is the bitwise ‘and’ of the integers INT1 and INT2.
4
&&~~ Used between two integers. The result is the bitwise ‘and’ of INT1 and the bitwise complement of INT2.
4
|| Used between two integers. The result is the bitwise ‘inclusive or’ of INT1 and INT2.
4
~~ Used in front of an integer. Produces the bitwise complement of INT.
4
||/& Used between two integers. The result is the bitwise ‘exclusive or’ of INT1 and INT2.
4
INT1 << N Used between two integers. Produces the bit pattern of INT shifted left by N positions.
4
INT1 >> N Used between two integers. Produces the bit pattern of INT shifted right by N positions.
4
/ Used to divide one number by another: NUM1 / NUM2.
4
** Used between two numbers: BASE ** POWER. Returns BASE raised to the power POWER.
3
rem Used between two integers: INT1 rem INT2. Returns the remainder, INT1 - (INT1 div INT2) * INT2.
2
div Used between two integers: INT1 div INT2. Performs integer division.
2
Operator Precedence
Precedences determine the parsing of complex expressions, especially unbracketed expressions with more than one infix operator. For example,
3 + 4 * 5
parses as3 + (4 * 5)rather than(3 + 4) * 5because the relative precedences dictate that * is to be parsed before +. Every operator in the CLEM language has a precedence value associated with it; the lower this value, the more important it is on the parsing list, meaning that it will be processed sooner than other operators with higher precedence values.
133 CLEM Language Reference
Functions Reference
The following CLEM functions are available for working with data in IBM® SPSS® Modeler. You can enter these functions as code in a variety of dialog boxes, such as Derive and Set To Flag nodes, or you can use the Expression Builder to create valid CLEM expressions without memorizing function lists orfield names.
Function Type Description
Information Used to gain insight intofield values. For example, the function
is_stringreturns true for all records whose type is a string. Conversion Used to construct newthe functionto_timestampfields or convert storage type. For example,converts the selected
field to a timestamp. Comparison
Used to comparefield values to each other or to a specified string. For example,<=is used to compare whether the values of twofields are lesser or equal.
Logical Used to perform logical operations, such asif,then,elseoperations.
Numeric Used to perform numeric calculations, such as the natural log of
field values.
Trigonometric Used to perform trigonometric calculations, such as the arccosine
of a specified angle. Probability
Return probabilities based on various distributions, such as probability that a value from Student’stdistribution will be less than a specific value.
Bitwise Used to manipulate integers as bit patterns.
Random Used to randomly select items or generate numbers.
String Used to perform a wide variety of operations on strings, such as
stripchar, which allows you to remove a specified character.
SoundEx Used tofind strings when the precise spelling is not known; based on
phonetic assumptions about how certain letters are pronounced.
Date and time Used to perform a variety of operations on date, time, and timestamp
fields.
Sequence Used to gain insight into the record sequence of a data set or performoperations based on that sequence. Global
Used to access global values created by a Set Globals node. For example,@MEANis used to refer to the mean average of all values for afield across the entire data set.
Blanks and null
Used to access,flag, and frequentlyfill user-specified blanks or system-missing values. For example,@BLANK(FIELD)is used to raise a trueflag for records where blanks are present.
Specialfields Used to denote the specificfields under examination. For example,
@FIELDis used when deriving multiplefields.
Conventions in Function Descriptions
The following conventions are used throughout this guide when referring to items in a function.
Convention Description
BOOL A Boolean, orflag, such as true or false. NUM,NUM1,NUM2 Any number.
Convention Description
INT,INT1,INT2 Any integer, such as1or–77. CHAR A character code, such as`A`.
STRING A string, such as"referrerID".
LIST A list of items, such as["abc" "def"].
ITEM Afield, such asCustomerorextract_concept.
DATE A datefield, such asstart_date, where values are in a format such asDD-MON-YYYY.
TIME A timefield, such aspower_flux, where values are in a format such asHHMMSS.
Functions in this guide are listed with the function in one column, the result type (integer, string, and so on) in another, and a description (where available) in a third column. For example, the following is the description of theremfunction.
Function Result Description
INT1 rem INT2 Number Returns the remainder ofexample, INT1divided byINT2. For
INT1 – (INT1 div INT2) * INT2.
Details on usage conventions, such as how to list items or specify characters in a function, are described elsewhere. For more information, see the topicCLEM Datatypeson p. 127.