I don't think that there is any way to recover from the singular matrix error with the INV function, so the initial test must be done if you go this route.
Please check the 3rd code example above as this is not doing what you think. Specifically, the statement "if rank(MATRIX)=&SIZE." will always evaluate as false, so GINV is used for all the simulations, and the timings are more a reflection of how much slower GINV is when compared to INV. The RANK function in IML returns the rank order of the elements within a matrix. To get the matrix rank, you will have to use one of the methods in Rick's article, see link in the original topic which contains code for a RankMatrix function, however this will be expensive as the preferred methods involve the calculation of an SVD or a generalized inverse.
... View more