See Crunch Automation basics for more information.
The REORDER CATEGORIES command allows you to change the order of categories on categorical and categorical array variables. It does not create a new variable—it just changes the order on an existing variable(s).
You can refer to the categories by category ID (code) or the label.
When used on multiple variables, the variables will need to have the same number of categories. They either need to have the same category IDs or they need to have the same labels. Any category codes not declared will remain in the original order.
REORDER CATEGORIES alias, ..., alias ORDERED code|"label", ..., code|"label";
The following examples are part of the 2019 Mobile Technology and Home Broadband 2019 case study.
Declaring an order (alphabetical order of categories)
Consider the following variable (the default import appears on the left side). We can reorder the categories by descending order of size so that they appear as they do on the right side:
REORDER CATEGORIES cregion ORDERED "South", "West", "Midwest", "Northeast”;
Reversing a scale (on a categorical array)
As part of the setup, a categorical array was created:
CREATE CATEGORICAL ARRAY sns2a, sns2b, sns2c, sns2d, sns2e LABELS "Twitter", "Instagram", "Facebook", "Snapchat", "Youtube" AS sns2_cat TITLE "Frequency of Social Media" DESCRIPTION "Thinking about the social media sites you use... About how often do you visit or use....?";
...for which the categories can be reversed:
REORDER CATEGORIES sns2_cat ORDERED 5,4,3,2,1;