Introduction
Speed up your data import by creating a script.
Requirements
- The importdata.zip file, which includes the data file we will use for this article.
Method
In a QScript, the project
variable represents your Q project. In order to import a new data set, we need to apply the addDataFile
method to our project
variable. The basic arguments are as follows:
addDataFile(data_file, override_file_name, options)
- The data_file argument assumes that the data file is in the same location as the QScript file so only requires the data file's name and extension.
- The override_file_name should be set to null for Q.
- The options argument lets you optionally tell Q to do the following:
auto_tidy_labels
- Automatically clean up variable labels.auto_detect_questions
- Automatically identify and combine multiple-response and grid questions.strip_labels_html
- Strip HTML from variable labels.- Note, these are all set to false by default.
Now let's look at our example:
var data_file = project.addDataFile("Phone.sav", "null", { auto_tidy_labels: true,
auto_detect_questions: true,
strip_labels_html: true });
- In this case, we will import the Phone.sav file as a data set and allow Q to tidy the data set using all 3 cleaning options.
- By additionally declaring this as
data_file
, we can then perform other QScript functions on this data set where necessary. - Note, this
addDataFile
QScript method is designed only for when you need to upload a new data set to your project.
Next
How to Create a Custom QScript