CONVERT (schema command)
See Crunch Automation basics for more information.
The CONVERT command allows you to confirm or alter the types of the mentioned variables, to ensure they have the expected type later in the script.
Only in cases of converting to categorical is it possible to indicate which codes should be assigned to each of the values of the original column.
In situations where the input variables are the same as the target type, it won’t fail and instead will work as a confirmation of the type.
If the input variable is a derived categorical variable, it will return an error since it’s not possible to perform casting with options to a derived variable.
For columns with integer values, it is possible to omit the CODE argument and it will then assign the integer value of each row as its category code. Under this usage, the "label" is required. Any number present in the data and not mentioned in the command will default to the next available free code and use a string version of its numeric value as the category name.
CONVERT alias, ..., alias TO (CATEGORICAL|NUMERIC|TEXT) [WITH VALUE "string"|number TO ["label"] [CODE code [MISSING]], ..., VALUE "string"|number TO ["label"] [CODE code [MISSING]], ];
CONVERT var1, var2 TO NUMERIC; CONVERT var3, var4 TO CATEGORICAL WITH VALUE "a" TO CODE 1 MISSING, VALUE "b" TO CODE 2; CONVERT var3, var4 TO CATEGORICAL WITH VALUE 1 TO "First", VALUE 2 TO "Second", VALUE 3 TO "Third";