MBANALYSIS Procedure

Example 21.1 Training a Model

Note: Input data must be in a table that is accessible in your session. You can refer to this table by using a two-level name. The first level is a libref, and the second level is the table name. For more information, see the section Using SAS Viya Workbench in Chapter 2, Shared Concepts.

This example trains the model by using data that are available in the sampsio.Assocs data set. This data set contains 1,000 transactions of 1,000 customers; each transaction contains information about the customer, time, and item or product. The customer (ID) variable is named Customer. The target variable is named Product, and the time variable is ignored. To perform association discovery, the input data table must have a separate observation for each product that is purchased by each customer. You must assign the ID role to one variable and the target model role to another variable when you create the data source. Only one variable is supported as the customer variable and only one variable is supported as the target variable.

You can load the sampsio.assocs data set into your SAS library in the following DATA step. These statements assume that your SAS libref is named mylib, but you can substitute any appropriately defined SAS libref.

data mylib.assocs;
   set sampsio.assocs;
run;

The following DATA steps create two hierarchies, mylib.firstLevel and mylib.secondLevel:

data mylib.firstLevel;
  length Item $20 Category $20;
    Item='apples'; Category='Fruits'; output;
    Item='artichok'; Category='Vegetables'; output;
    Item='avocado'; Category='Fruits'; output;
    Item='baguette'; Category='Bread'; output;
    Item='bordeaux'; Category='Wine'; output;
    Item='bourbon'; Category='Whisky'; output;
    Item='chicken'; Category='Non-Veg'; output;
    Item='coke'; Category='Cold-Drink'; output;
    Item='corned_b'; Category='Non-Veg'; output;
    Item='cracker'; Category='Vegetables'; output;
    Item='ham'; Category='Non-Veg'; output;
    Item='heineken'; Category='Beer'; output;
    Item='hering'; Category='Non-Veg'; output;
    Item='ice_crea'; Category='Cold-Drink'; output;
    Item='olives'; Category='Vegetables'; output;
    Item='peppers'; Category='Fruits'; output;
    Item='sardines'; Category='Non-Veg'; output;
    Item='soda'; Category='Cold-Drink'; output;
    Item='steak'; Category='Non-Veg'; output;
    Item='turkey'; Category='Non-Veg'; output;
 run;
data mylib.secondLevel;
  length Category $20 Dept $20;
    Category='Fruits'; Dept='Breakfast'; output;
    Category='Vegetables'; Dept='Breakfast'; output;
    Category='Bread'; Dept='Breakfast'; output;
    Category='Wine'; Dept='Drinks'; output;
    Category='Whisky'; Dept='Drinks'; output;
    Category='Non-Veg'; Dept='Breakfast'; output;
    Category='Cold-Drink'; Dept='Drinks'; output;
    Category='Beer'; Dept='Drinks'; output;
 run;

The following statements run the association analysis on the mylib.assocs data table:

proc mbanalysis data=mylib.assocs items=10 support=1 separator="\*"
   nLHS_range=(2,3) nRHS_range=(4,5) antecedentList=("Fruits")
   consequentList=("Non-Veg");
   output out=mylib.out outfreq=mylib.outfreq outrule=mylib.outrule;
   customer Customer;
   target product;
   hierarchy data = mylib.firstLevel mylib.secondLevel;
   savestate rstore=mylib.myStateArm;
run;

The DATA= option names the input data table to be analyzed. The ITEMS= option specifies the number of items in a rule. The SUPPORT= option specifies the minimum level of support for a rule. The SEPARATOR= option specifies separator character in the antecedent (left-hand side) or consequent (right-hand side) of a rule. The NLHS_RANGE= option specifies range of number of items in the left-hand side (LHS) of a rule. The NRHS_RANGE= option specifies range of number of items in the right-hand side (RHS) of a rule. The ANTECEDENTLIST= option specifies the regular expression strings to match in the antecedent of a rule. The CONSEQUENTLIST= option specifies the regular expression strings to match in the consequent of a rule. The OUTPUT statement specifies output tables to contain results of the MBANALYSIS procedure. The CUSTOMER statement requests that the Customer variable be used to group the target variable into baskets. The TARGET statement requests that the Product variable be used as the target variable. The HIERARCHY statement specifies the item’s hierarchies. The RSTORE= option in the SAVESTATE statement specifies the binary scoring file to be used for scoring.

Last updated: September 23, 2026