Adding Data Files
Jump to navigation
Jump to search
This page describes how to add files programmatically. See Multiple Data Files for instructions for adding a data file from the menus. Adds a data file to a project.
// Add phone.sav as an extra data file to the current project.
var data_file = project.addDataFile("phone.sav", null, { auto_tidy_labels: true,
auto_detect_questions: false,
strip_labels_html: true });
This code imports the phone.sav data file and assigns the resulting project to a variable. Key aspects of the code are:
- project.addDataFile("phone.sav", null, true, false, true) causes the phone.sav file to be imported, where the first true indicates that the labels in the file are to be auto-tidied, the false indicates the questions are not to be auto-detected and the true at the end indicates that HTML should be removed from any labels.
- null could be replaced by an ID if using the HTTP API.
- var data_file = project… assigns the data file to a variable called data_file. Later code then uses this variable. Importantly, variable in this context just means an object of some kind; it is a much more general concept that the idea of a column of data in a data file.
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.