# String banding

This conversion bands (or bins) textual data. It is typically used to make a standard and easy to use banded version of text string data. This banded version is convenient for the FastStats end user for point and click selection and Cross Tabs etc.

> [!NOTE]
>
> String banding operations can be calculated “on the fly” from a numeric variable by using FastStats and the results can be saved as virtual variables.

The same operations can be performed as Post-Load Scripts. However it is sometimes useful to band text strings at the build stage.

To produce a banded selector: define the selector over the top of the field that contains the value. This is most easily achieved using an [Alias](<https://help.apteco.com/en/designer/data-source/data-source-controls/index.md>). The [Decodes](<https://help.apteco.com/en/designer/define-variables/selector-decodes/index.md>) for a string band include descriptions that specify the range.

## String bands

Individual ranges on string variables can have any one of the following syntax:

- `AAA - BBB` representing any string starting AAA to any string starting BBB inclusive.
- `AAA` representing exactly AAA.
- `AAA - AAA` representing any string starting AAA e.g. AAAX, AAAB
- `> AAA` representing any string alphabetically greater than AAA
- `< AAA` representing any string alphabetically less than AAA
- `>=AAA` representing any string alphabetically greater than or equal to AAA
- `<=AAA` representing any string alphabetically less than or equal to AAA

Any strings that include `-`, `>`, `<`, `*`, `?` must have the whole string enclosed in speech quotes (“).

Ranges can also be formed by entering a string containing the standard ‘*’ and ‘?’ wildcards. The ‘*’ character wildcard can match any string including spaces whereas the ‘?’ character wildcard matches exactly one character. You can include as many wildcards in your string as required.

## Examples of wildcard ranges

r?b would match rob, rib, rub but not root or rb.

*pp* would match any string containing “pp” e.g. appropriate, hippo, pp, ppp etc.

*p?p* would match any string containing “p?p” e.g. pop, hipppy, p2p but not hippy

> [!NOTE]
>
> You cannot specify ranges containing wildcards e.g. *pp* - r? is invalid.

For banding, a record will be classified into the first range that it satisfies.

The following examples illustrate how FastStats interprets some typical string ranges (assume the string is defined as 4 characters in length in this case):

| Range | Interpretation |  | Note |
| --- | --- | --- | --- |
| Description | Lower | Upper |  |
| ABC | ABC | ABC | \- |
| ABC - ABC | ABC\# | ABC$ | \- |
| ABCD - ABCF | ABCD | ABCF | \- |
| A\\\* | A\#\#\# | A$$$ | \- |
| 1 - 9 | 1\#\#\# | 9$$$ | \- |
| \>=AB | AB\#\# | $$$$ | \- |
| \\\<= DOG | \#\#\#\# | DOG$ | \- |
| \>LOTS | LOTS | $$$$ | \- |

In the above examples interpret \# as “first alphabetic character” and $ as “last alphabetic character”.

All bands are treated as inclusive at both ends and a value will be selected once under the first band that it falls into. Invalid bands are ignored.

> [!NOTE]
>
> **Example**
>
> Band the customer surname into 4 bands plus a catch-all band.
>
> | Code | Description |
> | --- | --- |
> | ! | Unclassified |
> | A | A - F |
> | B | G - L |
> | C | M - R |
> | D | S - Z |
