Given pressure is directly proportional to density, my understanding is that you can use the pressure of gas in a container to calculate the mass of the gas in the container. My reasoning being;
$p=k\rho$ ($p$ = pressure and $\rho$ = density)
Then;
$\rho = \frac{m}{V}$ ($m$ = mass and $V$ = Volume)
Therefore;
$\frac{p}{k} = \frac{m}{V} \rightarrow m = \frac{pV}{k}$.
This means that assuming $k$ is kept constant (i.e. constant temperature etc.) the pressure in the container should be directly proportional to the mass of the gas in the container, and therefore you can calculate the mass of gas in the container by using the pressure.
My first question is whether this is correct? And my second question is, assuming this is correct, would this still be accurate if the container is in use i.e. gas is being added/removed from the container, or would this only work when the container is sealed with no pipes in or out?