Is it right that in SAS IML, it is not possible to multiply to get product of two matrices if they contain missing value ??
There is no solution for this problem in SAS ???
Is it right that in SAS IML, it is not possible to multiply to get product of two matrices if they contain missing value ??
There is no solution for this problem in SAS ???
According to the IML Documentation on missing values, you are correct: it is not possible to multiply two matrices that contain a missing value (or more) using matrix multiplication (elementwise is fine). This is stated as for efficiency reasons; I'm not sure what that entails, but presumably there are some linear algebra shortcuts that IML uses which wouldn't work as well if missing values were possible.
Remember that 'missing' isn't actually a value in the backend; it's a particular negative value (lowest possible negative number, in fact) which SAS knows to handle in a certain way when it does math with it.
If you want to use missings, you could re-code them to a very low negative number much larger than any possible value in your data, like -999999, and then after the multiplication is done, re-code negative values (or large negative values) back.
Here's an example:
proc iml;
xvar = {1 1,2 2};
yvar = {-99999 2,1 1};
zvar = xvar*yvar;
do z=1 to nrow(zvar) ;
if zvar[z,1] < 0 then do;
zvar[z,1]=.;
end;
end;
print zvar;
quit;
This only works if your values are always positive, and -999999 must be big enough that it outweighs any possible addition done with it (so -1 wouldn't work, for example, as then you have -1*1+1+1=0). If you have missings in both matrices, you would have to also filter the large positive values out (and again, this would only work if your data allowed for it; many circumstances would cause this to have undesirable results.)
I wrote a blog post that discusses various ways to interpret multiplication with missing values. The article "Matrix multiplication with missing values in SAS" also includes SAS/IML code that enables you to multiply matrices that contain missing values.