See Crunch Automation basics for more information.
REPLACE CATEGORICAL ARRAY CASE is a schema-block command that allows you to overwrite values in a categorical array by defining conditions and the new categories or variable to use for those values.
It follows the same rules as the CREATE CATEGORICAL ARRAY CASE command, but there is no support for an ELSE or VARIABLE statements.
All of the conditions must evaluate to masks of the same column width as the variable you are replacing.
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.
Syntax
REPLACE CATEGORICAL ARRAY CASE my_array1
WHEN condition THEN "label" [CODE int [NUMERIC VALUE <float>] [MISSING]]
...
WHEN condition THEN "label" [CODE int [NUMERIC VALUE <float>] [MISSING]]
END;
Example
REPLACE CATEGORICAL ARRAY CASE my_array1
WHEN my_array1 == 1 THEN "NA"
WHEN my_array2 == 3 THEN "Two" CODE 20
END;