SPATIALREG Procedure

Compact Representation of Spatial Weights Matrix

When the number of spatial units n increases, the amount of memory that it takes to store n squared entries of the spatial contiguity matrix bold upper C or the spatial weights matrix bold upper W increases dramatically. To circumvent the storage issue, PROC SPATIALREG enables you to provide a compact representation of bold upper W (or bold upper C) when appropriate. With the compact matrix representation, you provide a data set that contains three variables by using the WMAT= option. The first two variables identify the row r and column c of bold upper W (or bold upper C), and left-parenthesis r comma c right-parenthesis can be expressed either as numerical indices or as values of the variable specified in the SPATIALID statement. The third variable contains the nonzero value of bold upper W (or bold upper C) for row r and column c. With this compact representation, the number of observations in the data set specified in the WMAT= option equals the total number of nonzero entries in bold upper W (or bold upper C).

You must use a SPATIALID statement if you want to use the compact representation of the spatial contiguity or spatial weights matrix. With the compact representation, the first two variables of the data set that you specify in the WMAT= option must be of the same type. First, the first two columns in that data set can be row and column index for each nonzero entry in bold upper W (or bold upper C). In this case, the SPATIALID variable is numeric type. Alternatively, the first two columns in the WMAT= data set can be characters that are the names of two neighboring spatial units in bold upper W (or bold upper C). In this second case, the SPATIALID variable is character type.

For example, the compact representation of the spatial weights matrix bold upper W,

bold upper W equals Start 4 By 4 Matrix 1st Row 1st Column 0 2nd Column 0.5 3rd Column 0 4th Column 0.5 2nd Row 1st Column 1 2nd Column 0 3rd Column 0 4th Column 0 3rd Row 1st Column 0 2nd Column 0 3rd Column 0 4th Column 1 4th Row 1st Column 0.5 2nd Column 0 3rd Column 0.5 4th Column 0 EndMatrix

would look like the following:

data Ws;
  input SID cSID Weight;
  datalines;
  1 2 0.5
  1 4 0.5
  2 1 1.0
  3 4 1.0
  4 1 0.5
  4 3 0.5
  ;
run;

For the spatial contiguity matrix bold upper C,

bold upper C equals Start 4 By 4 Matrix 1st Row 1st Column 0 2nd Column 1 3rd Column 0 4th Column 1 2nd Row 1st Column 1 2nd Column 0 3rd Column 0 4th Column 0 3rd Row 1st Column 0 2nd Column 0 3rd Column 0 4th Column 1 4th Row 1st Column 1 2nd Column 0 3rd Column 1 4th Column 0 EndMatrix

the compact representation would look like the following:

data Cs;
  input SID cSID Weight;
  datalines;
  1 2 1.0
  1 4 1.0
  2 1 1.0
  3 4 1.0
  4 1 1.0
  4 3 1.0
  ;
run;

If the spatial weights matrix is the same as matrix bold upper W in the section k-Order Binary Contiguity Matrices, its compact representation would be as follows:

data Ws2;
  input SID $ cSID $ Weight;
  datalines;
  L1 L2 0.5
  L1 L4 0.5
  L2 L1 1.0
  L3 L4 1.0
  L4 L1 0.5
  L4 L3 0.5
  ;
run;

If the spatial contiguity matrix is the same as matrix bold upper C in the section k-Order Binary Contiguity Matrices, its compact representation can be given in the data set Cs2 as follows:

data Cs2;
  input SID $ cSID $ Weight;
  datalines;
  L1 L2 1.0
  L1 L4 1.0
  L2 L1 1.0
  L3 L4 1.0
  L4 L1 1.0
  L4 L3 1.0
  ;
run;
Last updated: June 19, 2025