This article describes how to create, edit, and run QScripts in Q. QScript is an advanced feature that can help you to automate repetitive tasks, such as setting up data, cleaning data, recoding data, or creating tables and charts.
Many programs can only be used with scripting (e.g., R) or are more efficiently used via scripting (e.g., SPSS’s syntax). In Q, most things are done faster and easier by selecting multiple tables or variables and dragging-and-dropping and using menus. Furthermore, many advanced functions are already pre-built or are done automatically so most users would not need to use QScripts.
Nevertheless, QScript is useful in the following situations:
- When needing to make the same change to a large number of variable sets (e.g., creating top 2 box scores, or combining Agree with Strongly agree on lots of different variable sets).
- When needing to follow a similar process to the creation and formatting of a large number of tables or charts.
See QScript Examples Library for examples.
Requirements
- Q version Q4.10 and higher
Method
Create a QScript
1. You can create a new QScript from the toolbar via Automate > Open QScript (Macro) Editor. This Editor allows you to write JavaScript code.
2. Once you have entered your code, press the Play button.
3. You can save this to a specified location via the Save button.
Run a QScript from the Online Library
Built-in QScripts are found in the toolbar under Automate > Browse Online Library and are identified with a script icon to the left of their name:
These scripts run as soon as they are selected.
Run or Edit an Existing QScript
1. If you create a QScript in a text editor outside of Q, you can run it directly via Automate > Run QScript (Macro) Editor from File and selecting your script.
2. If you wish to view or edit an existing script saved to your computer, you can load it in the QScript Editor via Automate > Open QScript (Macro) Editor, pressing the Open folder icon, and selecting your script.
3. If you wish to view or edit an existing script from the Online Library, you can search for it in the Search features and data field at the top, select the relevant QScript page, and click Edit a Copy below the page that pops up on the right.
Next
How to Create a Custom QScript