FACTMAC Procedure

Getting Started: FACTMAC Procedure

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 shows how to use the FACTMAC procedure to learn a factorization machine model from observations in a SAS data table. This example uses the cars data set in the Sashelp library and illustrates the prediction of gas mileage of cars based on make and model. The analysis uses four variables: car make, car model, car type, and a variable named mpg_city, which measures the car’s fuel usage (in miles per gallon) for city driving. The remaining variables in the data table are not used.

You can load the cars data set into your SAS library in the following DATA step:

data mylib.cars;
   set sashelp.cars;
run;

These statements assume that your SAS libref is named mylib, as in the section Using SAS Viya Workbench, but you can substitute any appropriately defined SAS libref.

The following statements run PROC FACTMAC and output the results to ODS tables:

proc factmac data=mylib.cars outmodel=mylib.factors maxiter=50
             nfactors=5  learnstep=0.002;
   input make model type /level=nominal;
   target mpg_city  /level=interval;
   output out=mylib.score_out copyvars=(make model type mpg_city);
run;

proc print data=mylib.factors(obs=48);
run;

The NFACTORS= option requests that the model estimate five factors, the LEARNSTEP= option sets the optimization learning step to 0.002, the MAXITER= option requests that the optimization stop after 50 iterations, and the OUTMODEL= option requests that the model parameters be written to the mylib.factors data table. The INPUT statement specifies that the make, model, and type variables are to be used as nominal inputs. The TARGET statement specifies that mpg_city is the target variable to be predicted. The OUTPUT statement requests that the predictions be written to the data table mylib.score_out and that the make, model, type and mpg_city variables be copied from the mylib.cars data table to the mylib.score_out data table.

Figure 1 shows the global bias, the bias values for each level, and the list of the factors for the first 48 observations.

Figure 1: Bias Values and Factors

ObsVariableLevelBiasFactor1Factor2Factor3Factor4Factor5
1_GLOBAL_ 20.06070.000000.000000.000000.000000.00000
2MakeAcura-0.6322-1.65189-2.342130.09553-4.065510.72563
3MakeAudi-1.5871-0.231310.07828-0.35298-0.45827-0.20166
4MakeBMW-1.36070.007770.05455-0.19466-0.072720.22275
5MakeBuick-1.17192.964930.108153.14048-4.74293-0.28692
6MakeCadillac-3.5607-1.07033-0.991871.496990.582450.95669
7MakeChevrolet-0.39410.012160.006880.053210.00923-0.03507
8MakeChrysler-0.19410.56168-0.90681-0.77899-1.384981.48220
9MakeDodge-0.67610.536030.050440.036140.798670.46522
10MakeFord-0.7999-0.29532-0.164540.05845-0.275500.10528
11MakeGMC-4.68571.03171-1.97310-0.91069-4.544182.00952
12MakeHonda7.76280.84902-0.54073-0.37149-0.87898-0.31334
13MakeHummer-10.0607-3.266522.06044-3.31811-1.32709-6.03068
14MakeHyundai2.93930.300750.72757-0.780570.01371-0.13113
15MakeInfiniti-2.8107-1.202702.237626.27459-3.971310.51608
16MakeIsuzu-4.06076.31966-4.610522.32465-5.98882-2.33495
17MakeJaguar-2.5607-2.18175-1.36395-1.720342.885731.22202
18MakeJeep-2.72741.34136-4.715435.687400.25748-5.30474
19MakeKia1.8483-5.307553.53864-4.756195.244462.55098
20MakeLand Rover-6.0607-5.986571.735013.160500.16469-3.89031
21MakeLexus-2.6062-0.970681.834401.616610.778150.44383
22MakeLincoln-3.28301.326840.16185-0.68375-0.661961.17094
23MakeMINI6.4393-0.183161.88514-0.79716-2.625575.78783
24MakeMazda1.3938-0.911711.95718-1.132410.701240.06483
25MakeMercedes-Benz-2.7146-0.167380.07799-0.20517-0.25945-0.08443
26MakeMercury-2.50520.933932.256070.173570.257861.27973
27MakeMitsubishi0.8623-0.244320.356350.167030.32479-0.02810
28MakeNissan-0.3549-0.00132-0.025610.007510.00230-0.02652
29MakeOldsmobile0.93930.210733.498565.92790-6.289792.92394
30MakePontiac0.4847-0.13061-1.70502-1.350861.145991.41535
31MakePorsche-2.6322-4.902594.562694.185550.66543-4.09505
32MakeSaab0.3678-0.186660.007140.161810.804390.61889
33MakeSaturn4.31431.90340-3.380203.730030.31785-0.34106
34MakeScion11.43936.31009-6.229946.26170-1.744815.77012
35MakeSubaru0.21200.48494-0.36550-0.41698-0.496961.03908
36MakeSuzuki2.0643-1.727731.93579-0.77099-0.01766-1.50695
37MakeToyota4.36780.29650-0.08574-0.136810.20477-0.54623
38MakeVolkswagen1.3393-0.052360.70879-1.49191-1.339240.19614
39MakeVolvo-0.31070.91585-0.20479-0.64416-0.231660.74650
40Model3.5 RL 4dr-2.06074.290086.321276.32609-6.32203-4.13052
41Model3.5 RL w/Navigation 4dr-2.0607-2.533581.070336.322444.641850.88841
42Model300M 4dr-2.06076.332586.32102-1.461056.325446.32405
43Model300M Special Edition 4dr-2.0607-6.333474.20158-6.32730-0.689464.77917
44Model325Ci 2dr-0.06070.75687-6.321716.32257-6.324596.32309
45Model325Ci convertible 2dr-1.06076.33216-4.54598-0.492666.324966.32270
46Model325i 4dr-0.0607-0.113594.989792.211395.501776.32416
47Model325xi 4dr-1.0607-6.325391.493045.52169-6.133256.32568
48Model325xi Sport-1.06076.32095-5.18676-0.45827-4.11622-3.12254


Last updated: September 23, 2026