$g$ is not necessarily a constant if you consider it as "the gravitational acceleration at point A on Earth", and more so if you consider other planets.
$g$ varies around the earth--since the distance from the center of the earth varies. $g$ at mount Everest is lesser than $g$ elsewhere.
Aside from that, $g$ on the moon is approximately one-sixth of $g$ on Earth. So $g$ can vary.
Anyway, one can include relevant dimension-ed constants while doing dimensional analysis. In fact, one has to do so. Otherwise, with dimensional analysis, you will get the wrong expression--since by multiplying/dividing by a power of the dimensioned constant (which you will have to do sooner or later to make it dependant on the constant), the dimensions of the result change. Aside from this, you may have a two-equations-three-variables moment.
A more intuitive reason for why we include dimensioned constants--you can imagine that they changed, and predict the result based on that. In most cases anyway, the constant is not truly a constant, like $g$. The only "true" constants are $G,c,\hbar,R$, and parameters of various bodies. And some other stuff I probably forgot.