Clean/process data

Illustration showing two people exchanging data between a CSV file and dashboard charts with floating numbers. One person holds a purple folder labeled "CSV" while numbers flow between them and computer screens displaying bar charts.

Even for the best designed surveys, you may need to do additional data cleaning and refactoring. You can make changes to data in a tool like Excel, then upload into Protobi. But there is also the option to change survey data programmatically within the app. 

You can add processes to: 

Why data clean in Protobi?

One way to change data is in SPSS, SAS, R, Excel, or another tool to edit the data prior to uploading it to Protobi as a data table. This might be the easiest solution for one-time changes. But you can do some serious data processing in Protobi as well.  

One advantage of making changes to data in Protobi is that all your processing code is in one place, neatly organized, with changes tracked. So if you get new data, or later need to review the changes you made, it's all visible in one place.

Protobi uses JavaScript to process data

Protobi can execute code written in JavaScript. JavaScript is a powerful first-class language comparable to C, Perl, and Python which can do many things (and possibly do them more easily than you could in SPSS or SAS).  

Add a data process

In the data tab of project settings press the green "+ New process" button to add a data process.

Protobi Project settings page for "Training - Tiffany" showing the Data section with three panels: Data tables (with "main" table marked as Primary), Processes (with "+ New process" button highlighted), and Documents section. The left sidebar shows navigation options including Open, Overview, Wiki pages, Data (selected), Permissions, and other settings.

You will be prompted to give the process a name:

Browser dialog from app.protobi.com with heading "Enter a unique table name" and text input field containing "process". Two buttons appear below: "Cancel" (white) and "OK" (blue).

From the process table, press "Edit/Run". 

Protobi Data table page showing configuration for the "process" table. The form displays fields including Name: "process", Type: "process", Process type dropdown set to "Simple", Updated timestamp "Wed Dec 02, 2020 09:26 pm", and admin buttons for Edit/Run, Delete, and Make primary.

You will be taken to the code-view page. There is default return data code that simply returns whatever data file in the "main" table.

Beneath that there are some comments, and some pre-written code with two backslashes at the front of the code. Slashes in front of code means it will not work and will be read as a comment. 

Protobi Data process editor for "process" (simple) showing JavaScript code. The code editor displays "return data['main']" on line 1, followed by comments explaining the process structure including "var rows = data['main']" and "rows.forEach(function(row)" with tutorial link to https://help.protobi.com/advancedusers/process-data-in-protobi. Save and Run buttons appear in the top right.

Delete the code in line one. Then, delete the double slashes (//) from the front of the pre-written code. It should like like screenshot below. 

Run code on every respondent row

From here, you can start adding javascript inside the "rows.forEach" function which runs the code within it on every row in the data. In most cases that means every respondent record, but it some cases it might be every patient case record, etc. It depends if your data has stacked survey loops.

Protobi Data process editor showing expanded JavaScript code example. The code includes commented tutorial text referencing https://help.protobi.com/advancedusers/process-data-in-protobi, followed by executable code: "var rows = data['main']" on line 6, "rows.forEach(function(row) {" on line 7, comment "// do something for each row..." on line 8, closing brace "})" on line 9, and "return rows;" on line 10.