MKTATTRIBUTION Procedure

Getting Started: MKTATTRIBUTION Procedure

This section provides a brief example of using the Markov attribution model that the MKTATTRIBUTION procedure supports.

Consider a market attribution model that has the following transition probability matrix (TPM) for five states StartSet c h a n n e l Baseline 1 comma c h a n n e l Baseline 2 comma c h a n n e l Baseline 3 comma c o n v e r s i o n comma n u l l EndSet:

StartLayout 1st Row  bold upper A equals Start 5 By 5 Matrix 1st Row 1st Column 0.0 2nd Column 0.2 3rd Column 0.4 4th Column 0.3 5th Column 0.1 2nd Row 1st Column 0.1 2nd Column 0.0 3rd Column 0.4 4th Column 0.5 5th Column 0.0 3rd Row 1st Column 0.3 2nd Column 0.2 3rd Column 0.0 4th Column 0.3 5th Column 0.2 4th Row 1st Column 0.0 2nd Column 0.0 3rd Column 0.0 4th Column 1.0 5th Column 0.0 5th Row 1st Column 0.0 2nd Column 0.0 3rd Column 0.0 4th Column 0.0 5th Column 1.0 EndMatrix EndLayout

It also has the following initial state probability vector (ISPV):

StartLayout 1st Row  pi equals Start 5 By 1 Matrix 1st Row  0.3 2nd Row  0.3 3rd Row  0.4 4th Row  0.0 5th Row  0.0 EndMatrix EndLayout

The following statements simulate the channel visit history, or the customer journey, for 100 customers from the previous model in order to provide test data for PROC MKTATTRIBUTION. The test data table has three columns: customerId is the ID of each customer, t is the time period that the customer was in, and c is the channel that the customer visited at time t. Column c takes value i for channel i, i equals 1, 2, and 3, and takes a value of 0 when customer conversion occurs. For a customer, if the last column c value is not 0, this means that the customer is not converted, which also means that the customer is in the null state. Note that, the channel variable takes the natural numbers sequentially from 1 and can’t skip any numbers.


%let seed=1234;
%let T=10; *the maxsimustep for each customer;
%let nCustomers=100; *the number of customers;

data simu(keep = customerId t c);

  call streaminit(&seed);

  array p0[5] _temporary_ (0.3, 0.3, 0.4, 0, 0.0);
  array p1[5] _temporary_ (0, 0.2, 0.4, 0.3, 0.1);
  array p2[5] _temporary_ (0.1, 0, 0.4, 0.5, 0.0);
  array p3[5] _temporary_ (0.3, 0.2, 0, 0.3, 0.2);
  do customerId = 1 to &nCustomers;
    c_last=0;
    t=0;
    c=1;
    do while(t < &T. and 0<c<=3);
      c_last=c;
      t+1;
      if t=1 then
        c = rand("Table", of p0[*]);
      else do;
         if c_last=1 then
           c = rand("Table", of p1[*]);
         else if c_last=2 then
           c = rand("Table", of p2[*]);
         else if c_last=3 then
           c = rand("Table", of p3[*]);
      end;
      if c=4 then c=0;
      if c ne 5 then
        output;
    end; *for each customer;
  end; *for all simulations;
run;

proc print data=simu (obs=10) noobs; run;

data mylib.marketData; set simu; run;

The first 10 observations of the simulated data are shown in Figure 1.

Figure 1: Simulated Data

customerIdtc
113
120
211
223
311
323
330
411
423
431


The following statements estimate the Markov attribution model that has three channels:


proc mktattribution data=mylib.marketData;
   id section=customerId time=t;
   model c / nchannel=3;
run;

The model information and number of observations are shown in Figure 2.

Figure 2: Model Information and Number of Observations

The MKTATTRIBUTION Procedure

Model Information
Model TypeMarkov Attribution
Number of Channels3

Number of Observations288
Number of Missing Observations0


The estimates of the initial state probability vector are shown in Figure 3.

Figure 3: Estimates of Initial State Probability Vector

Initial State Probability
Vector
StateEstimate
Channel 10.32000
Channel 20.30000
Channel 30.38000
Conversion0.00000
Null0.00000


The estimated transition probability matrix is shown in Figure 4.

Figure 4: Estimated Transition Probability Matrix

Estimated Transition Probability Matrix
StateChannel 1Channel 2Channel 3ConversionNull
Channel 10.000000.223880.477610.223880.07463
Channel 20.103450.000000.396550.500000.00000
Channel 30.311830.139780.000000.279570.26882
Conversion0.000000.000000.000001.000000.00000
Null0.000000.000000.000000.000001.00000


The conversion rates are shown in Figure 5.

Figure 5: Conversion Rates

Conversion Rates
MethodRate
Data Based0.70000
Markov Chain0.70000


The value in the Data Based row is calculated from the input data. The value in the Markov Chain row is calculated by the estimated TPM. The removal effect of a channel is the decrease in the probability of overall conversion if the channel were removed.

The removal effects are shown in Figure 6.

Figure 6: Removal Effects

Removal Effects
ChannelEffect
10.36540
20.40962
30.42932


The contributions are the normalized removal effects to indicate each channel’s contribution to the conversion. The contributions of each channel through the Markov attribution model and the other three heuristic attribution models are shown in Figure 7.

Figure 7: Channel Contributions

Channel Contributions
ChannelMarkov ChainFirst TouchLast TouchLinearPosition
Based
Time Decay
10.303400.300000.214290.270880.263520.26259
20.340120.357140.414290.369420.375950.37726
30.356480.342860.371430.359690.360520.36015


Last updated: July 09, 2026