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