String Expressions

Create a Character String Variable

  1. Select Edit|Insert.
  2. Select Automatic Variable and click OK.
  3. Enter a variable name in the Variable Name box.
  4. Enter a variable label in the Variable Label box.
  5. Select String Expression from the Type of data to be stored drop-down box.
  6. Enter a calculation in the Numeric Calculation/String Expression box.
  7. Click OK.

Substituting Different Text Strings

Sometimes you may want to substitute different text strings depending on the response to a previous question. For example, if you have a set of questions asking:

  1. Who is your best friend? __________ [FRIEND]
  2. What is their gender? 1=Male, 2=Female, 8=Decline to Answer [GENDER]
  3. How long have you known “him”, “her”, or “them”? [KNOWN]

To substitute in “him”, “her”, or “them” depending on the response to GENDER, you can add an Automatic Variable with the following options:

  • Variable Name: SUB_GENDER
  • Type of data to be stored: String Expression
  • Variable Label: Substitution based on gender
  • Numeric Calculation/String Expression: IF(GENDER = 1, 'him', IF(GENDER = 2, 'her', 'them'))

String Expression Automatic Variable example

You would insert your new Automatic Variable text by using a substitution token in your Data Element question text:

  • How long have you known &[SUB_GENDER]?

Substitution token in Data Element question text example

Using Automatic Variables for Dates

A common application of Automatic Variables is to calculate dates prior to or after a given date. For example, you might want to ask:

In the last 60 days— that is, since &[PAST60D]—how many times have you …?

where PAST60D is the date 60 days prior to today.

First, create an Automatic Variable named TODAY of the type Today’s Date. Next, create an Automatic Variable with the following options:

  • Variable Name: PAST60D
  • Type of data to be stored: String Expression
  • Variable Label: Date past 60 days ago
  • Numeric Calculation/String Expression: LONGDATE(TODAY - 60)

String Expression Automatic Variable example with dates

When this Variable (PAST60D) is used as a Substitution Token in the question: In the last 60 days—that is since &[PAST60D]—how many times have you …?, QDS will display: In the last 60 days—that is, since Saturday, June 22, 2016—how many times have you …?

Alternatively, you could enter:

SHORTDATE(TODAY-60)

This would display: In the last 60 days—that is, since 06/22/2016—how many times have you …?