Crunch Automation ๐Ÿ”—

The following describes the scripting language that Crunch provides in order to interact via the API. The system allows for an internal way of scripting that runs inside the Crunch app, which does not require any kind of development environment nor does it run any code on the userโ€™s computer.

The Crunch Automation system consists of a set of commands, which automate a pre-defined set of operations that the Crunch app allows via its UI. This includes creating filters, creating new derived variables, changing variable attributes, and so on.

Crunch Automation is executed via scripts, which are simply a plain text file that include a sequence of automation commands that run on existing datasets.

You must be the datasetโ€™s current editor in order to execute a Crunch Automation script on a dataset.

Writing a script ๐Ÿ”—

Scripts are plain flat-text files that consist of a list of commands, each terminated by a semicolon ; and a new line for the next command.

The commands are organized into schema commands and non-schema commands.

The schema commands must always be 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.

Comments ๐Ÿ”—

Scripts support comments. To write or comment any line, it must begin with the pound # character.

Variables ๐Ÿ”—

Variables are referred to by their unique alias in a dataset. If any RENAME command is used, then this how you should refer to the variable from that point onwards.

Aliases do not need quotation marks within the script unless they have spaces. If spaces are included, you can use the backtick (`) to escape them. For example:

# Example use of an alias without escaping
variable_alias

# Example of an alias that has spaces escaped
`alias with space`

Expressions ๐Ÿ”—

The Crunch Automation language allows you to use logical and arithmetic expressions in filters or other commands.

Parenthesis order is respected, and the following junctions are supported:

  • <
  • >
  • >=
  • <=
  • ==
  • AND
  • OR
  • +
  • -
  • *
  • /

Expressions have support for function calls, the following functions are supported:

  • is_missing(variable): Returns boolean type with True values on those rows that have a missing value.
  • is_valid(variable): Returns boolean type with True on rows that donโ€™t have a missing value.
  • duplicates(variable): Returns the column removing any repeated value. Returning only the first occurrence for each.
  • trim(numeric_variable, min_number, max_number): Replaces all values lesser than min_number and replaces them with it, same for max_number.
  • complete_cases([variable, ..., variable]): Returns the matching rows where values of all variables involved are not missing.
  • any_missing(array): Returns rows where any of the subvariables has a missing value.
  • all_missing(array): Returns rows where all of the subvariables have missing values.
  • all_valid(array): Returns rows where none of the subvariables have missing values.

Additionally, all boolean expressions can be wrapped in a NOT (expr) negation.

Example expressions:

CREATE FILTER Age > 18 AND (Gender = "F" OR Gender = "Female") NAME "Adult women";
CREATE FILTER favorite_browser IN ["Chrome", "Firefox"] AND NOT is_missing(answered) NAME "Top Browsers";
CREATE FILTER 3 <= rating < 8 AND (Age / 2) + 7 NAME "Medium rating dating range";
CREATE NUMERIC (2020 - Age) * 2 AS double_age NAME "Double Age";

Example script ๐Ÿ”—

# First commands specify the Schema block
CONVERT v1, v2 TO CATEGORICAL;
CONVERT v3, v4 TO NUMERIC;
RENAME v1 TO Age;
RENAME v2 TO Year;

# This is the first non-schema command; no schema commands are possible
# after this.
# Sets the exclusion filter on the dataset
SET EXCLUSION v3 < 0;

CREATE FILTER Age < 20 AS "Teenagers";

Running scripts ๐Ÿ”—

Following any datasetโ€™s shoji:entity representation, a scripts catalog will be linked.

To run a dataset, a client must perform a POST request with a shoji:entity to the scriptsโ€™ catalog with a body attribute containing the text contents of the script file inlined in the payload:

POST /api/datasets/123456/scripts/ HTTP/1.1

{
   "element": "shoji:entity",
   "body" {
   "body": "<Script contents>"
   }
}

The server will validate that the commands are consistent with the datasetโ€™s schema and return either a 202 response indicating a progress of the scriptโ€™s execution, or a 400 response with any detected errors.

Managing scripts ๐Ÿ”—

There is no management of scripts: once a script is executed, you cannot manage it any further after that. Its record exists as an execution log, as a reference of what changes were performed on it.

There is also no support to DELETE scripts. The only alternative to undo or delete a script is to revert the dataset to a savepoint before its execution.

Command reference ๐Ÿ”—

Schema commands ๐Ÿ”—

CONVERT ๐Ÿ”—

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 ommit the CODE argument and it will 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]],
   ];

Example

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";

RENAME ๐Ÿ”—

When handling unprocessed datasets, the aliases provided from the original file may not be adequate for the team that will process them. The RENAME command allows you to change the alias of variables.

Note, this command can only be used in the schema block of a script before creating any new variables.

RENAME alias, ..., alias TO alias, ..., alias;

Example

RENAME var1abc, var2cde TO var1, var2;

Non schema commands ๐Ÿ”—

REPLACE ๐Ÿ”—

This command allows you to replace the name, notes, and description for a list of variable aliases or for all variables.

REPLACE
    (NOTES|NAME|DESCRIPTION) IN
    alias, ..., alias
    WITH "string";

REPLACE (NOTES|NAME|DESCRIPTION) IN
    alias, ..., alias
    (LIKE|REGEX|REGEXP) "string" WITH "string";

REPLACE (NOTES|NAME|DESCRIPTION) WITH (NOTES|NAME|DESCRIPTION|ALIAS);

REPLACE (NOTES|DESCRIPTION)
   ON alias, ..., alias
   FROM alias, ..., alias;

Example

# Overwrite all variables' names with their descriptions.
REPLACE NAME WITH DESCRIPTION;

REPLACE NOTES IN random,pk,starttime WITH "System variables";
REPLACE NAME IN Age WITH "Respondent Age";
REPLACE DESCRIPTION IN q1...q5 WITH "subvariables";

REPLACE DESCRIPTION IN var1, var2 LIKE "Remove me" WITH "Replaced";
REPLACE DESCRIPTION IN var1, var2 LIKE "%begin" WITH "begin";
REPLACE DESCRIPTION IN var1, var2 REGEX "[abc]" WITH "+";
REPLACE DESCRIPTION IN var1, var2 REGEXP "last.*" WITH "last";

REPLACE NOTES ON var1, var2 FROM var3, va4;
REPLACE DESCRIPTION ON var5, var6 FROM var7, var8;

SET EXCLUSION ๐Ÿ”—

When necessary, this command allows you to set the datasetโ€™s exclusion filter to the desired expression.

SET EXCLUSION condition;

Example

SET EXCLUSION my_num1 > 10;

CREATE FILTER ๐Ÿ”—

Allows you to create arbitrary public filters for the dataset.

CREATE FILTER
  condition
NAME "string";

Example

CREATE FILTER
  wave_date >= 2019-07-01 AND wave_date < 2019-10-01
NAME "2019Q3";

CREATE MULTITABLE ๐Ÿ”—

Allows you to create arbitrary public multitables for the dataset, which indicates the labels and categories to hide for each variable.

CREATE MULTITABLE
   alias [([NAME "string"] [LABELS code|"label"="string", ..., code|"label"="string"] [HIDE code|"label", ..., code|"label"])],
   ...,
   alias [([NAME "string"] [LABELS code|"label"="string", ..., code|"label"="string"] [HIDE code|"label", ..., code|"label"])]
NAME "string";

Example

CREATE MULTITABLE
    age4 (HIDE "Missing"),
    gender (LABELS 1="M", 2="F"),
    multrace,
    wave (NAME "Period")
NAME "Demographics";

CREATE MULTITABLE
    age4 (HIDE "Missing"),
    gender (LABELS "Male"="M", "Female"="F"),
    multrace,
    wave
NAME "Demographics";

ORGANIZE ๐Ÿ”—

Newly uploaded datasets will have all its variables flat at the root folder without any organization. The ORGANIZE command allows you to put groups of variables into folders, leveraging nested trees. This command also allows you to organize variables under the secure variables tree.

If no path is provided, then one of root folders must be indicated, and the variables will be put in the root of that tree.

ORGANIZE alias, ..., alias INTO [SECURE|HIDDEN|ROOT] ["string"];

Example

ORGANIZE gender, age, country INTO "Basic|Demographics";
ORGANIZE q1_1, q1_2 INTO HIDDEN;
ORGANIZE ID, name INTO SECURE "|";

DISPLAY ๐Ÿ”—

The DISPLAY command sets subtotal properties to be displayed on card view for categorical variables. It works by indicating what subtotals to compute, based on a list of categories and where to show them on the variable card.

DISPLAY
    alias, ..., alias
    SUBTOTAL code|"label", ..., code|"label" LABEL "string" [AFTER CODE code|"label"]
    ...
    SUBTOTAL code|"label", ..., code|"label" LABEL "string" [AFTER CODE code|"label"]
[POSITION TOP|BOTTOM];

Example

DISPLAY
    approval, app2, app3, app
    SUBTOTAL 1,2 LABEL "Approve"
    SUBTOTAL 3,4 LABEL "Disapprove" AFTER CODE 2
POSITION BOTTOM;

DISPLAY
    approval, app2, app3, app
    SUBTOTAL "Approved", "Yes" LABEL "Approve"
    SUBTOTAL "Disapproved", "No" LABEL "Disapprove" AFTER CODE 2
POSITION BOTTOM;

LABEL CATEGORIES ๐Ÿ”—

Allows you to change the name of the categories on categorical variables. When used on multiple variables, all should have the exact same categories (in number and codes). The changes will happen in place on the same variable.

LABEL CATEGORIES
    alias, ..., alias
    WITH code|"label" AS "string", ..., code AS "string";

Example

LABEL CATEGORIES
    fav_browser, laptop_brand, fav_os
    WITH 9 AS "Not answered", 8 AS "Unknown";

LABEL CATEGORIES
    fav_browser, laptop_brand, fav_os
    WITH "NA" AS "Not answered", "NN" AS "Unknown";

REORDER CATEGORIES ๐Ÿ”—

Use the REORDER command to change the order of categorical variables. It will mutate the variable in place instead of creating a new variable. When used on multiple variables, they should all have the same categories (in number and codes). The category codes not mentioned on the order will be kept in the same order at the of the category list.

REORDER CATEGORIES
    alias, ..., alias
    ORDERED code|"label", ..., code|"label";

Example

REORDER CATEGORIES
    fav_browser, laptop_brand, fav_os
    ORDERED 1, 2, 8, 9;

REORDER CATEGORIES
    fav_browser, laptop_brand, fav_os
    ORDERED "First", "Second", "Third", "Fourth";

CREATE CATEGORICAL RECODE ๐Ÿ”—

Often, surveys will provide more categories than are desired for an analysis, so it is helpful to combine categories. For example, โ€œagreementโ€ type scales will give โ€œveryโ€, โ€œsomewhatโ€, and โ€œslightlyโ€ options that you want to combine into an overall โ€œagreeโ€ category.

CREATE CATEGORICAL
   RECODE alias, ..., alias
   MAPPING
      code|"label", ..., code|"label" INTO "label" [CODE value [MISSING]]
      code|"label", ..., code|"label" INTO "label" [CODE value [MISSING]]
      [ELSE "label" [INTO CODE value [MISSING]]|ELSE INTO NULL]
AS alias, ..., alias
[NAME "string", ..., "string"]
[DESCRIPTION "string", ..., "string"]
[NOTES "string", ..., "string"];

Example

CREATE CATEGORICAL
    RECODE v5, v6
    MAPPING
       4, 5 INTO "Likely" CODE 1
       3 INTO "Neutral" CODE 2
       1, 2 INTO "Unlikely" CODE 3
       ELSE INTO "Unaware" CODE 99 MISSING
AS "purchaselikelihood_1", "purchaselikelihood_2"
NAME "Purchase likelihood A combined", "Purchase likelihood B combined"
NOTES "Asked of those aware of each product";

CREATE CATEGORICAL
    RECODE v5, v6
    MAPPING
       "Likely", "Very likely" INTO "Likely" CODE 1
       "Neutral", "Don't care" INTO "Neutral" CODE 2
       "Unlikely", "Definitely not" INTO "Unlikely" CODE 3
       ELSE INTO "Unaware" CODE 99 MISSING
AS "purchaselikelihood_1", "purchaselikelihood_2"
NAME "Purchase likelihood A combined", "Purchase likelihood B combined"
NOTES "Asked of those aware of each product";

CREATE CATEGORICAL CASE ๐Ÿ”—

This allows you to assign specific values to categories based on a sequence of logical conditions. This is useful for creating segments or defining conditions based on multiple other variables, and not just recoding one. Rows that do not match any WHEN condition will be missing.

CREATE CATEGORICAL
   CASE
      WHEN condition THEN "label" [CODE value [MISSING]]
      ...
      WHEN condition THEN "label" [CODE value [MISSING]]
      [ELSE "string" [CODE value [MISSING]|ELSE INTO NULL]
   END
AS alias
[NAME "string"]
[DESCRIPTION "string"]
[NOTES "string"];

Example

CREATE CATEGORICAL
    CASE
        WHEN pid3 = "Democrat" AND ptystrength = "Strong"
            THEN "Strong Democrat" CODE 1
        WHEN pid3 = "Democrat" AND ptystrength = "Weak"
            THEN "Weak Democrat" CODE 2
        WHEN pid3 = "Independent" AND ptycloser = "Democrat"
            THEN "Lean Democrat" CODE 3
        WHEN pid3 = "Independent" AND ptycloser = "Neither"
            THEN "Independent" CODE 4
        WHEN pid3 = "Independent" AND ptycloser = "Republican"
            THEN "Lean Republican" CODE 5
        WHEN pid3 = "Republican" AND ptystrength = "Weak"
            THEN "Weak Republican" CODE 6
        WHEN pid3 = "Republican" AND ptystrength = "Strong"
            THEN "Strong Republican" CODE 7
        ELSE "Unknown party" CODE 9 MISSING
    END
AS "pid7"
NAME "Party Identification"
DESCRIPTION "7 category party identification scale"
NOTES "Recoded from pid3, ptystrength, and ptycloser";

CREATE CATEGORICAL CASE โ€ฆ THEN VARIABLE ๐Ÿ”—

CREATE CATEGORICAL
    CASE
        WHEN condition THEN VARIABLE alias
        ...
        WHEN condition THEN VARIABLE alias
        [ELSE "string" [CODE value [MISSING]|ELSE INTO NULL]
    END
AS alias
[NAME "string"]
[DESCRIPTION "string"]
[NOTES "string"];

Example

CREATE CATEGORICAL
    CASE
        WHEN a = 9 THEN "Not asked" CODE 9 MISSING
        WHEN a = 1 THEN VARIABLE a_1 #1=high 2=med 3=low
        WHEN a = 2 THEN VARIABLE a_2 #1=low 2=med 3=high
     END
AS my_case
NAME "My filled case";

CREATE CATEGORICAL ARRAY ๐Ÿ”—

Often, surveys will ask similar questions with identical response options about a number of things โ€” ratings of items is a common example of a โ€œgridโ€ of related columns of data. These can be grouped and displayed together as a Categorical Array in Crunch.

When providing the labels for the subvariables, it is possible to indicate to use the subvariables descriptions by indicating LABELS USE DESCRIPTIONS.

CREATE CATEGORICAL ARRAY
    alias, ..., alias
    LABELS ("string", ..., "string"| USE DESCRIPTIONS)
AS alias
[NAME "string"]
[DESCRIPTION "string"]
[NOTES "string"];

Example

CREATE CATEGORICAL ARRAY
    rating_1, rating_2, rating_3
    LABELS "Apple", "Lenovo", "Dell"
AS computer_ratings
DESCRIPTION "How likely are you to recommend your __ computer to friends?"
NAME "Ratings of Computers";

CREATE CATEGORICAL ARRAY
    rating_1, rating_2, rating_3
    LABELS USE DESCRIPTIONS
AS computer_ratings
DESCRIPTION "How likely are you to recommend your __ computer to friends?"
NAME "Ratings of Computers";

CREATE MULTIPLE DICHOTOMY FROM ๐Ÿ”—

This command creates new derived Multiple Response variables using an existing categorical array variable as input by indicating which code to use as a selected category.

The LABELS argument allows you to indicate alternative names that the subvariables will have on the new Multiple Response variable.

When using multiple inputs, you must indicate the same number of output aliases for each of the newly created multiple response variables.

CREATE MULTIPLE DICHOTOMY FROM
    alias, ..., alias
    [LABELS "string", ..., "string"]
    SELECTED code|"label", ..., code|"label"
AS alias, ..., alias
[NAME "string", ..., "string"]
[DESCRIPTION "string", ..., "string"]
[NOTES "string", ..., "string"];

Example

CREATE MULTIPLE DICHOTOMY FROM
    array1, array2
    LABELS "subvar1", "subvar2", "subvar3"
    SELECTED 1, 3
AS my_mr1, my_mr2
NAME "Multiple Response 1", "Multiple Response 2";

CREATE MULTIPLE DICHOTOMY FROM
    array1, array2
    LABELS "subvar1", "subvar2", "subvar3"
    SELECTED "Yes", "Maybe"
AS my_mr1, my_mr2
NAME "Multiple Response 1", "Multiple Response 2";

CREATE MULTIPLE DICHOTOMY ๐Ÿ”—

Allows you to create a Multiple response variable from a list of categorical subvariables. All the mentioned subvariables MUST have the same categories.

CREATE MULTIPLE DICHOTOMY
    alias, ..., alias
    [LABELS "string", ..., "string"]
    SELECTED code|"label", ..., code|"label"
AS alias
[NAME "string"]
[DESCRIPTION "string"]
[NOTES "string"];

Example

CREATE MULTIPLE DICHOTOMY
    cat1, cat2, cat3
    LABELS "Resp1", "Resp2", "Resp3"
    SELECTED 1
AS mymr
NAME "My Responses";

CREATE MULTIPLE DICHOTOMY
    cat1, cat2, cat3
    LABELS "Resp1", "Resp2", "Resp3"
    SELECTED "Yes"
AS mymr
NAME "My Responses";

CREATE NUMERIC ๐Ÿ”—

This command allows you to create a numeric variable from an arithmetic numeric expression.

CREATE NUMERIC
    expression
AS alias
[NAME "string"]
[DESCRIPTION "string"]
[NOTES "string"];

Example

CREATE NUMERIC
    (2020 - DoB) * 2
AS double_age
NAME "Age doubled";

CREATE CATEGORICAL CUT ๐Ÿ”—

This converts a numeric variable to a categorical one by defining boundaries between ranges. Itโ€™s useful to make numeric values simple to work with in tables, and are meaningful for their domain: respondent โ€œageโ€ in a small number of bins that become the basis of comparisons. In practice, surveys often use a hybrid numeric variable with effectively categorical sentinel values to indicate special missing values such as โ€œ-1โ€ for an otherwise positive range; or some โ€œhigh / out of boundsโ€ number such as โ€œ999โ€. Missing values indicated here are compared using strict equality and result in assignment to missing categories in the result, with optionally user-specified codes.

CREATE CATEGORICAL CUT
    alias, ..., alias
    BREAKS [MIN,] number, ..., number [, MAX] [closed LEFT|RIGHT]
    [LABELS "string" [CODE code] [MISSING], ..., "string" [CODE code] [MISSING]]
    [SET MISSING value ["string"] [CODE code], ..., value ["string"] [CODE code]]
AS alias, ..., alias
[NAME "string", ..., "string"]
[DESCRIPTION "string", ..., "string"]
[NOTES "string", ..., "string"];

Example

CREATE CATEGORICAL CUT my_num
   BREAKS 1, 10, 1000, MAX CLOSED LEFT
   LABELS "Too little" CODE 2 MISSING, "Just right" CODE 3, "Too much"
   SET MISSING 66 "NA" CODE 98, -9 CODE 99
AS my_cut;

CREATE WEIGHT ๐Ÿ”—

Allows to create a variable to be used as a weight via the rake function. Permits to to use multiple categorical variables as input and set different weights for each of categories.

CREATE WEIGHT
   RAKE
      alias TARGETS value=float, ..., value=float
      alias TARGETS value=float, ..., value=float
   [TRIM MIN=float MAX=float]
AS alias
[NAME "string"]
[DESCRIPTION "string"]
[NOTES "string"];

Example

CREATE WEIGHT
   RAKE
      var0 TARGETS 1=0.4, 2=0.6
      var1 TARGETS 1=0.3, 2=0.4, 3=0.3
   TRIM MIN=0.1 MAX=10
AS my_wt_var
NAME "Name"
DESCRIPTION "Description"
NOTES "Notes";

CREATE LOGICAL ๐Ÿ”—

Allows to create a logical variable from an expression that evaluates to boolean. This variable can be later used for filtering or conditions.

CREATE LOGICAL
   expression
AS alias
   [NAME "string"]
   [DESCRIPTION "string"]
   [NOTES "string"];

Example

CREATE LOGICAL
   gender == "F" or gender == "f"
AS females
NAME "Female panelists"
DESCRIPTION "Only female panelists";

SET MISSING ๐Ÿ”—

Use this command to change whether a category is set to be โ€œmissingโ€ and excluded from the base of percentages. When used on multiple variables all should have the exact same categories (in number and codes). The changes will happen in place on the same variable.

SET [NOT] MISSING code|"label", ..., code|"label" IN alias, ..., alias;

Example

SET MISSING 98, 99 IN Age, Gender;
SET NOT MISSING 1, 2 IN Age, Gender;

SET MISSING "Not Asked", "NA" IN Age, Gender;
SET NOT MISSING "Yes", "No" IN Age, Gender;

SET WEIGHT ๐Ÿ”—

This command allows to set a number of numeric variables as available weights for the dataset users.

SET WEIGHT alias, ..., alias;

Example

SET WEIGHT rake_1, rake_2;

SET NUMERIC VALUE ๐Ÿ”—

This command allows to change the categories on a variable indicating what numeric value each category should have. It allows to change multiple variables at once, they all must be categorical and have the same matching categories.

SET NUMERIC VALUE alias, ..., alias
   WITH
      code|label = float|NULL,
      ...
      code|label = float|NULL;

Example

SET NUMERIC VALUE var1, var2 WITH
   1 = 1.61,
   2 = 2.71,
   3 = 3.14;

CREATE MULTIPLE SELECTION ๐Ÿ”—

This command allows to create a multiple response variable when each of the involved subvariables have different categories and different selected code. All the involved variables must be categoricals (arrays not allowed).

The list of selected categories will correspond by position to each of the variables mentioned. Similarly, for labels, unless itโ€™s been instructed to use each variableโ€™s names, a list of matching strings should be included to use as the names of each of the subvariables, else will use the name of the selected category for each variable as the default.

CREATE MULTIPLE SELECTIONS
   alias, ..., alias
   SELECTED code|"label", ..., code|"label"
   [LABELS [FROM (NAME|DESCRIPTION|NOTES)]|"label", ..., "label"]
AS alias
[NAME "string"]
[DESCRIPTION "string"]
[NOTES "string"];

Example

CREATE MULTIPLE SELECTIONS
   admire1, admire2, admire3, admire4, admire5
   SELECTED 1,2,3,4,5
   LABELS "Apple", "Borland", "Corel", "Dbase", "eViews"
AS new_multiple_response;

SET DATES ๐Ÿ”—

This command lets you date attributes on each category for categorical variables. All dates must be valid ISO-8601 format strings.

SET DATES alias, ..., alias
   WITH
      code|label = "date"|NULL,
      ...
      code|label = "date"|NULLL;

Example

SET DATES var1, var2 WITH
   1 = "1983-02-25",
   2 = "1970-01-01",
   3 = NULL;

CREATE CATEGORICAL INTERACTION ๐Ÿ”—

This command will create a new categorical variable with categories resulting from the cartesian product of the input categorical variables. It is possible to indicate the desired categories based on each combination of the input categories.

CREATE CATEGORICAL INTERACTION A, B
   [WITH
       (code, ..., code) INTO "label" CODE code,
       ...
       (code, ..., code) INTO "label" CODE code]
AS alias
[NAME "string"]
[DESCRIPTION "string"]
[NOTES "string"];

Example

CREATE CATEGORICAL INTERACTION Age, Gender
   WITH
       (1, 1) INTO "Young men" CODE 100,
       (1, 2) INTO "Young women" CODE 101,
       (2, 1) INTO "Adult men" CODE 102,
       (2, 2) INTO "Adult women" CODE 103
AS age_x_gender;