May I treat units (e.g. joules, grams, etc.) in equations as variables?
Yes, you may. It is quite common to convert units into each other. The simplest conversion might be the prefixing of units, e.g. 
$$\mathrm{\frac{km}{m}}=1000 \Longleftrightarrow \mathrm{1~km = 1000~m}.$$

Another example is the interconversion of units of energy. In some parts of chemistry, it is still quite common to use calories, in others Joule, as a SI unit, has taken its place.
$$\mathrm{\frac{cal}{J}}=4.184 \Longleftrightarrow \mathrm{1~cal = 4.184~J}.$$

In principle, all units are defined to be constants, special numbers in a wider sense. You can treat them as such.