See Crunch Automation basics for more information.
About schema commands
Schema is a complete, low-level description of the type of each variable used for validation and integrity checking—data that conforms to a schema is valid. The schema RENAME/REPLACE commands must always appear at the top of the script, since they can change the schema of the dataset on which they’re running.
After the first non-schema command is declared, the app returns an error if any schema command is found subsequently in the script (i.e., after the schema commands run, the schema for the dataset becomes immutable).
Crunch Automation makes the schema immutable to avoid further mistakes and alignment issues (for appending data). If applicable, you should make changes to the schema prior to running the script to address any errors that occur in data collection.
You can also use the CREATE CONVERT command to create derivations (of a different variable type and alias), which are not schema-changing by definition.
About the RENAME command
The RENAME command allows you to change the alias of variables. As noted in the previous section, it is a schema-changing command and cannot be run again after the first non-schema command subsequently runs.
Generally speaking, you don’t need to change aliases of variables, so you only need to do this if there's a good reason. A common reason is needing to align a dataset: for example, you run the same survey on two different survey platforms and then want to merge them together via an append. The aliases of the variables don’t align (e.g., the “Gender” question is d1 in the first survey and q1 in the second survey). Thus, the RENAME command allows you to fix the alignment in one of the datasets.
RENAME (alias, ..., alias | <alias-function>) TO (alias, ..., alias | <refunction>);
Use case
In the following example, we’ve imported the Core Trends Study SPSS file example. The variables display in the variable summaries view as seen in the following:
# Rename one alias
RENAME lang TO Language;
# Rename multiple aliases at a time
RENAME lang, cregion TO Language, Region;
RENAME ALL("numeric") TO SUFFIX(ALIAS, "_num");
RENAME LIKE("str_%") TO REMOVE_COMMON_PREFIX(ALIAS);
After Crunch Automation runs the script, the following appears in the variable summaries view: