Creating a Banner

From Q
Jump to navigation Jump to search

Using QScript to create a Banner question called Demographic banner. In most cases it is not necessary to create banners with a script because banners can be created using Create > Banner > Drag and Drop. This example uses 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 data_file = project.dataFiles[0];
data_file.createBanner("Demographic banner",
                                  [[data_file.getQuestionByName("Age")],
                                   [data_file.getQuestionByName("Gender")],
                                   [data_file.getQuestionByName("Work status")]]);


Note that:

  • The new Question that is constructed in the Q Project has the name Demographic banner.
  • The banner contains three non-nested questions: Age, Gender and Work status. We can see that they are not nested by the square brackets surrounding each of the calls to the questions. By contrast, the following script nests gender within age:
// Working on Phone.sav, this creates a new banner question
// that can be selected from the blue or brown dropdown,
// with the name "Demographic banner with nesting".
var data_file = project.dataFiles[0];
data_file.createBanner("Demographic banner with nesting",
                       [[data_file.getQuestionByName('Age'), data_file.getQuestionByName('Gender')],
                        [data_file.getQuestionByName("Work status")]]);

See also