I probably would do this in base SAS too, but it's also quite doable in IML. I use the unique-loc method to convert your ABC into numeric values, and then use the FULL
function to square the matrix:
data have;
input P1 $ P2 $ Score;
datalines;
A A 1
A B 2
A C 5
B B 4
B C 9
C A 3
C B 6
;;;;
run;
proc iml;
use have;
read all var _NUM_ into have_mat;
read all var _CHAR_ into p_mat;
p1_unique = unique(p_mat[,1]); *get unique values of p1;
p2_unique = unique(p_mat[,2]); *get unique values of p2;
num_mat = j(nrow(p_mat),3,0); *generate empty matrix to populate;
do i = 1 to ncol(p1_unique); *code the p1 values;
idx = loc(p_mat[,1] = p1_unique[i]);
num_mat[idx,2] = i; *sparse matrix format requires 2nd col be row values;
end;
do i = 1 to ncol(p2_unique); *code the p2 values;
idx = loc(p_mat[,2] = p2_unique[i]);
num_mat[idx,3] = i; *sparse matrix format requires 3rd col be col values;
end;
num_mat[,1] = have_mat; *and first col is the values for the matrix itself;
final_mat = full(num_mat); *FULL() function creates a square matrix and fills with 0s;
print final_mat;
quit;