Rebasing a Pick One Question
This page describes how to rebase data automatically using a QScript. If you are just looking to rebase a single question it is easier to do so directly on the table - see Hiding and Removing Categories (Missing Values).
This removes the 'Don't know' category from a Pick One question and sets it as missing (i.e., so that the table is automatically rebased when the question is used).
This example can be run in C:\Program Files\Q\Examples\Phone.sav (this may be located on a different place on your computer depending upon how Q was installed).
var age = project.dataFiles[0].getQuestionByName('Age');
var dk_value = age.valueAttributes.getSourceValueByLabel("Don't know");
age.valueAttributes.setIsMissingData(dk_value, true);
The second line of this code works out what value has been assigned to 'Don't know' in the data file.
The third line sets this value as missing (i.e., which is equivalent to right-clicking on the category in the Outputs Tab and selecting Remove.
See also
- Next worked example.
- QScript for an explanation of how to run this code.
- QScript Examples Library for other examples.
- QScript Reference for technical information.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.