# pseg()

Here’s how to use pseg() function.

## A.pseg( x,y )

Description

Return the sequence number of the interval in which the parameter falls.

Syntax

A.pseg(x,y)

Note

The function returns the sequence number of the interval in which y falls in sequence A, which must be an ordered one. By default the sequence members form intervals that are left-closed and right-open. Parameter x is an expression which will be calculated over each member of sequence A.

In the cases where y is not a member of A, if y is less than the smallest member of an increasing sequence A (or y is greater than the largest member of a decreasing sequence A), then return 0; if y is greater than or equal to the largest member of an increasing sequence A (or y is less than or equal to the smallest member of a decreasing sequence A), then return the length of A.

Parameters

 A A sequence x An expression, which is a field name or a legal expression made up of field name and in which the sign ~ can be used to reference the current record; can be absent y An expression

Options:

@r  Form intervals that are left-open and right-closed

Return value

The sequence number of the interval to which y belongs

Example

 A 1 [2,22,122,222,2222] 2 =A1.pseg(12) 1. The intervals formed by members of the sequence are [2,22), [22,122), [122,222), [222,2222) and [2222,∞) 3 =A1.pseg(2222) 5 4 =A1.pseg@r(2222) 4 5 [1,4,8] 6 =A5.(~+~).pseg(10) 2 7 =A5.pseg(~+~,10) 2; the expression is equivalent to A6’ s expression 8 =A1.pseg(1) 0