|Related Online Training modules|
|Generally it is best to access online training from within Q by selecting Help : Online Training|
Part 5 of Creating and Modifying Variables (Video) |
- 2 Accessing variables as arrays
- 6 Examples
- 8 Buttons, options and fields
- Filling in the fields:
- Name A short description of the variable containing no spaces or special characters.
- Label The Label used in reporting.
if (age < 39) 1; else 2
(brandA + brandB + brandC) / daysInYear
- Pressing OK.
They are also created automatically when using various other functions in Q (e.g., if creating a Banner question).
Accessing variables as arrays
Right-click on the variable in the Variables and Questions tab and select Edit Variable.
If you have missing values for variables used to in the Expression you do not explicitly address this using the isNaN function or if statements, observations in the constructed variable will have missing values for any of the observations for which there are missing values on any of the variables used in their construction.
- How to Create a Categorical Variable from Binary Variables
- Creating a Family Size Variable
- Computing State from Postcode (Zip Code)
Variables can be automatically created by:
- Creating one variable and using Use as Template for Replication to automatically create other similar variables. This approach is best if there is an obvious structure to the Expression that needs to be modified for each variable (e.g., q3_a+1, q3_b+1, q3_c+1,...).
- Creating linked variables and modifying the Expression field. See:
- Writing QScript to automatically create variables (in particular, see the various examples listed in the QScript Examples Library).
Buttons, options and fields
Name The name of the variable to be created.
Label The label of the variable to be created.
Expression Box in which the formula is entered for constructing a variable. All standard mathematical operations can be used (e.g., +, /, *, brackets, etc). Examples of formula include:
age / 2 and
Variables List of variables that can be used in the Expression box. Selected by pressing the down arrow. Right-clicking on a variable opens the Value Attributes dialog box for the variable.
Also see How to Create a Date Variable.
Access all data rows Treats the variables as arrays; requires that the Expression returns an array. See Access All Data Rows.
Check Code Checks that the formula in the Expression box contains no errors.
Save Saves the edited variable. Use this when you want to save the current expression, but want to keep this window open and continue making changes. (Shortcut: CTRL+S)
New Saves the current variable and then starts editing a new blank variable (afterwards, you can click the left arrow button to come back to the current variable). (Shortcut: CTRL+N)
This category has only the following subcategory.
The following 8 pages are in this category, out of 8 total.