Modifying Footers - Display SPSS Custom Attribute

From Q
Jump to: navigation, search

This Rule shows the comment from the question selected in the blue drop-down in the footer of the table. Q will automatically create variable comments when your SPSS data file contains custom attributes. SPSS custom attributes may contain information about the original survey design (such as the original question text), making it useful to include this information in the footer of tables. You may manually edit these comments in the Variables and Questions Context Menu.

This Rule allows you to optionally enter prefix text that will be removed from the start of all comments. For example, if your comment was "Question text: Choose your gender", then you would enter "Question text: " (including the space) as your prefix, resulting in a final table footer of "Choose your gender".

Technical details

This Rule requires Q 4.11 or later.

How to apply this rule

For the first time in a project

  • Select the table(s)/chart(s) that you wish to apply the rule to.
  • Start typing the name of the Rule into the Search features and data box in the top right of the Q window.
  • Click on the Rule when it appears in the QScripts and Rules section of the search results.

OR

  • Select Automate > Browse Online Library.
  • Choose this rule from the list.

Additional applications of the rule

  • Select a table or chart that has the rule and any table(s)/chart(s) that you wish to apply the rule to.
  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to apply.
  • Click on the Apply drop-down and choose your desired option.
  • Check New items to have it automatically applied to new items that you create. Use Edit > Project Options > Save as Template to create a new project template that automatically uses this rule.

Removing the rule

  • Select the table(s)/chart(s) that you wish to remove the rule from.
  • Press the Rules tab (bottom-right corner).
  • Press Apply next to the rule you wish to remove and choose the appropriate option.

How to modify the rule

  • Click on the Rules tab (bottom-left of the table/chart).
  • Select the rule that you wish to modify.
  • Click Edit Rule and make the desired changes. Alternatively, you can use the JavaScript below to make your own rule (see Customizing Rules).

JavaScript

function main() {
    if (fileFormatVersion() < 8.77) {
        alert('This Rule requires a newer version of Q (i.e., 4.11 or newer).');
        return;
    }

    var lbl_prefix = form.newLabel('Comment prefix (will be removed):');
    var txt_prefix = form.newTextBox('txtPrefix');
    form.setInputControls([lbl_prefix, txt_prefix]);

    var comment = table.blueQuestion.variables[0].comment;
    if (comment) {
        var prefix = txt_prefix.getValue();
        if (prefix && comment.length >= prefix.length && comment.substring(0, prefix.length) == prefix)
            comment = comment.substring(prefix.length);

        var footers = table.extraFooters;
        footers.push(comment);
        table.extraFooters = footers;
    }
}


form.setHeading('Modifying Footers - Display SPSS Custom Attribute');
form.setSummary('Modifying Footers - Display SPSS Custom Attribute');
main();

See also