Step 2: Defining Categories (R)
You define categories for each dimension using the SetCategories method.
Example
table = spss.BasePivotTable("Table Title",
"OMS table subtype")
coldim=BasePivotTable.Append(table,Dimension.Place.column,"coldim")
rowdim1=BasePivotTable.Append(table,Dimension.Place.row,"rowdim-1")
rowdim2=BasePivotTable.Append(table,Dimension.Place.row,"rowdim-2")
cat1=spss.CellText.String("A1")
cat2=spss.CellText.String("B1")
cat3=spss.CellText.String("A2")
cat4=spss.CellText.String("B2")
cat5=spss.CellText.String("C")
cat6=spss.CellText.String("D")
cat7=spss.CellText.String("E")
BasePivotTable.SetCategories(table,rowdim1,list(cat1,cat2))
BasePivotTable.SetCategories(table,rowdim2,list(cat3,cat4))
BasePivotTable.SetCategories(table,coldim,list(cat5,cat6,cat7))
- You set categories after you add dimensions, so the
SetCategories
method calls follow theAppend
orInsert
method calls. - The first argument to
SetCategories
is a reference to theBasePivotTable
object--in this example, the R variable table. - The second argument to
SetCategories
is an object reference to the dimension for which the categories are being defined. - The third argument to
SetCategories
is a single category or a list of unique category values, each expressed as a CellText object (one ofCellText.Number
,CellText.String
,CellText.VarName
, orCellText.VarValue
). When you specify a category as a variable name or variable value, pivot table display options such as display variable labels or display value labels are honored. In the present example, we use string objects whose single argument is the string specifying the category. - It is a good practice to assign variables to the
CellText
objects representing the category names, since each category will often need to be referenced more than once when setting cell values.

Note: Generation of the resulting table requires more code than is shown here.