Common Data Formatting Techniques

  1. Asterisk Padding
    #### → *****####

  2. Date Formatting
    (See the date variable formatting page)

  3. Manual ZIP+4 Formatting
    ######### → #####-####

  4. Masking Data
    ####### → ****###

  5. Phone Number Formatting
    ########## → (###) ###-####

  6. Removing Zero Padding
    00000#### → ####

  7. Reversing Comma Separated Names
    LAST NAME, FIRST NAME → FIRST NAME LAST NAME

  8. Social Security Number Formatting
    ######### ###-##-####

  9. Spelled Out Dollar Amount
    123.45 → one hundred twenty three dollars and forty five cents
    (See the text variable formatting page)

  10. Zero Padding
    #### → 00000####

  11. Comma Formatting
    1234567.00 → 1,234,567.00
    (See also the floating point/real/currency formatting page)

Asterisk Padding

(For the purposes of this example, the data to be formatted is stored in a variable named "DATA")

  1. Create a new text variable for the padded data.
    (PADDED DATA will be used for this example)

  2. Create a function below the variable definition to pad the data:
    Result variable = PADDED DATA
    Function = Format
    Parameter 1 = variable, DATA
    Parameter 2 = fixed, %12s
    (replace "12" with the desired padding length)
  3. Create a function below the padding function:
    Result variable = PADDED DATA
    Function = Regular expression
    Parameter 1 = variable, PADDED DATA
    Parameter 2 = fixed,

    • Replace all spaces with asterisks
      s/\s/*/g
    • Replace leading spaces with asterisks:
      s/\G\s/*/g
  4. PADDED DATA now has the formatted string.


Manual ZIP+4 Formatting

(For the purposes of this example, the data to be formatted is stored in a variable named "ZIP CODE")

  1. Create a new text variable for the formatted ZIP code
    (FORMATTED ZIP will be used for  this example)

  2. Create a function below the variable definition to format the ZIP code
    Result variable = FORMATTED ZIP
    Function
    = Regexp
    Parameter 1 = variable, ZIP CODE
    Parameter 2
    = fixed,

    s/(\d{5})(\d{4})/$1-$2/
  3. FORMATTED ZIP now has the formatted string


Masking Data

(For the purposes of this example, the data to be masked is stored in a variable named "DATA")

  1. Create a new text variable for the masked data
    (MASKED DATA will be used for  this example)

  2. Create a function below the variable definition to mask the data
    Result variable = MASKED DATA
    Function
    = Regexp
    Parameter 1 = variable, DATA
    Parameter 2
    = fixed,

    s/\G.(?=.{3})/*$1/g
  3. MASKED DATA now has the formatted string


Phone Number Formatting

(For the purposes of this example, the data to be formatted is stored in a variable named "PHONE NUMBER")

  1. Create a new text variable for the formatted phone number
    (FORMATTED PHONE NUMBER will be used for  this example)

  2. Create a function below the variable definition to format the phone number
    Result variable = FORMATTED PHONE NUMBER
    Function
    = Regexp
    Parameter 1 = variable, PHONE NUMBER
    Parameter 2
    = fixed,

    s/(\d{3})(\d{3})(\d{4})/($1) $2-$3/
  3. FORMATTED PHONE NUMBER now has the formatted string


Remove Zero Padding

(This can be done directly when defining a text field/variable with the "Remove Zeros" function)

(For the purposes of this example, the data to be formatted is stored in a variable named "DATA")

  1. Create a new text variable for the formatted data
    (FORMATTED DATA will be used for  this example)

  2. Create a function below the variable definition to format the data
    Result variable = FORMATTED DATA
    Function
    = Remove Zeros
    Parameter 1 = variable, DATA

  3. FORMATTED DATA now has the formatted string


Reversing Comma Separated Names

(This can be done directly when defining a text field/variable with the "Reverse Text" function with a "," in the parameter text box to the right of the function drop-down)

(For the purposes of this example, the name to be reversed is stored in a variable named "NAME")

  1. Create a new text variable for the reversed name
    (REVERSED NAME will be used for  this example)

  2. Create a function below the variable definition to reverse the name
    Result variable = REVERSED NAME
    Function
    = Reverse Text
    Parameter 1 = variable, NAME
    Parameter 2
    = fixed, ","

  3. REVERSED NAME now has the formatted string


Social Security Number Formatting

(For the purposes of this example, the data to be formatted is stored in a variable named "SSN")

  1. Create a new text variable for the formatted Social Security number
    (FORMATTED SSN will be used for  this example)

  2. Create a function below the variable definition to format the Social Security number
    Result variable = FORMATTED SSN
    Function
    = Regexp
    Parameter 1 = variable, SSN
    Parameter 2
    = fixed,

    s/(\d{3})(\d{2})(\d{4})/$1-$2-$3/
  3. FORMATTED SSN now has the formatted string


Zero Padding

(For the purposes of this example, the data to be formatted is stored in a variable named "DATA")

  1. Create a new text variable for the padded data.
    (PADDED DATA will be used for this example)

  2. Create a function below the variable definition to pad the data:
    Result variable = PADDED DATA
    Function = Format
    Parameter 1 = variable, DATA
    Parameter 2 = fixed, %12s
    (replace "12" with the desired padding length)
  3. Create a function below the padding function:
    Result variable = PADDED DATA
    Function = Regular expression
    Parameter 1 = variable, PADDED DATA
    Parameter 2 = fixed,

    • Replace all spaces with zeros
      s/\s/0/g
    • Replace leading spaces with zeros:
      s/\G\s/0/g
  4. PADDED DATA now has the formatted string.


Comma Formatting

(For the purposes of this example, the data to be formatted is stored in a variable named "DATA")

  1. Create a new text variable for the formatted data with commas.
    (COMMA FORMATTED DATA will be used for this example)

  2. Create a function below the variable definition to pad the data:
    Result variable = COMMA FORMATTED DATA
    Function = Regular Expression
    Parameter 1 = variable, DATA
    Parameter 2 = fixed,
    s/(\d)(?=(?:\d{3})+(?:\.|$))/$1,/g
  3. COMMA FORMATTED DATA now has the formatted string.


0 Comments

Article is closed for comments.
Powered by Zendesk