width(X)

Returns the string length of the input value.

Syntax

width(X)

Input

Argument Type Description
X any A column name

Return Value

Returns an integer value corresponding to the number of characters of the input value. If X is a number, the result is the width of string(X).

If X is N/A, the result is 0.

Sample Usage

value width(value)
'Los Angeles' 11
5 1
10 2
N/A 0

Example

In the "Monthly Statewide Seasonally Adjusted Unemployment Statistics" table (pub.fin.fred2.bls.smsa), you can create a computed column that displays the number of characters of the values in the unemp_rate column:
<base table="pub.fin.fred2.bls.smsa"/>
<willbe name="example" value="width(unemp_rate)" label="Width of`Rate"/>

For a value of 6.6, the result would be "3".

For a value of 11.0, the result would be "2".

You can create a computed column that displays the number of characters of the values in the month column:
<willbe name="month_example" value="width(month)" label="Width of`Month"/>
For a value of 01/76, the result would be "6" because the value of the underlying integer in <month> form is 197601, which is 6 characters in length. It is displayed as 01/76 in the table because of the display format applied to the month column.

Additional Information

  • This function does not work with Unicode (UTF-8) strings.
  • For a Unicode-compliant alternative, consider strlen(X).