Create a Calculated Variable in Data Sets

Overview

Calculated variables can be generated that are calculated within and across forms to result in a new variable in a data set.  The calculation can simply add two variables or it may include if-else logic.  Any VBScript or JavaScript function can be used.  The data definition of the calculated variable is transferred to statistical packages when exporting the data.

Required Role(s)

  • Data Set Management

Examples

 

Steps

  1. From the Data Sets main menu item, edit an existing data set or create a new data set
  2. Select New Calculated Variable from the toolbar
  3. Attributes tab
    1. Name:  The name of the calculated variable
    2. Description:  An optional description
    3. Code:  A unique name, within the project, for the calculated variable
    4. Include Missing: A checkbox indicating whether to include missing values
  4. Variable Finder Tab
    1. Add variables to be used in the calculated variable by clicking the Add icon
    2. See Variable Finder for more details
    3. Click here for a description of the Interval column
  5. Expression tab
    1. Language:  Select either JavaScript or VBScript
    2. Expression: Enter a simple expression using the variable's alias or call a function to use a complex expression
    3. User Defined Functions: Define the function using the language selected and the variable's alias.
  6. Pick List tab (Optional)
    1. Pick list options can be defined
    2. Click on the Add icon to add a pick list element
    3. Change the Value, if needed, to match the values returned on the Expression tab
    4. Enter a Name for the pick list element
  7. Click Continue
  8. Click Save and Return or Save


Example of the Expression tab using JavaScript: