We consider the moduli space of stable torsion free sheaves of any rank on a smooth projective threefold. The singularity set of a torsion free sheaf is the locus where the sheaf is not locally free. On a threefold it has dimension $\leq 1$. We consider the open subset of moduli space consisting of sheaves with empty or 0-dimensional singularity set. For fixed Chern classes $c_1,c_2$ and summing over $c_3$, we show that the generating function of topological Euler characteristics of these open subsets equals a power of the MacMahon function times a Laurent polynomial. This Laurent polynomial is invariant under $q \leftrightarrow q^{-1}$ (upon replacing $c_1 \leftrightarrow -c_1$). For some choices of $c_1,c_2$ these open subsets equal the entire moduli space. The proof involves wall-crossing from Quot schemes of a higher rank reflexive sheaf to a sublocus of the space of Pandharipande-Thomas pairs. We interpret this sublocus in terms of the singularities of the reflexive sheaf.