You not only can, but also must treat symbols for units by the ordinary rules of algebra, since unit symbols are mathematical entities and not abbreviations.
The value of a quantity is expressed as the product of a number and a unit. That number is called the numerical value of the quantity expressed in this unit.
This relation may be expressed in the form
$$Q = \left\{ Q \right\} \cdot \left[ Q \right]$$
where $Q$ is the symbol for the quantity, $\left[ Q \right]$ is the symbol for the unit, and $\left\{ Q \right\}$ is the symbol for the numerical value of the quantity $Q$ expressed in the unit $\left[ Q \right]$.
For example, the mass of a sample is
$$m = 100\ \mathrm g$$
Here, $m$ is the symbol for the quantity mass, $\mathrm g$ is the symbol for the unit gram (a unit of mass), and $100$ is the numerical value of the mass expressed in grams. Thus, the value of the mass is $100\ \mathrm g$.
It is important to distinguish between the quantity $Q$ itself and the numerical value $\left\{ Q \right\}$ of the quantity expressed in a particular unit $\left[ Q \right]$. The value of a particular quantity $Q$ is independent of the choice of unit $\left[ Q \right]$, although the numerical value $\left\{ Q \right\}$ will be different for different units.
For example, changing the unit for the mass in the previous example from the gram to the kilogram, which is $10^3$ times the gram, leads to a numerical value which is $10^{-3}$ the numerical value of the mass expressed in grams, whereas the value of the mass stays the same.
$$m = 100\ \mathrm g = 0.100\ \mathrm{kg}$$
Since symbols for units are mathematical entities, both the numerical value and the unit may be treated by the ordinary rules of algebra. For example, the equation $m = 100\ \mathrm g$ may equally be written
$$m/\mathrm g = 100$$
It is often convenient to label the axes of a graph in this way, so that the tick marks are labelled only with numbers. The quotient of a quantity and a unit may also be used in this way for the heading of a column in a table, so that the entries in the table are all simply numbers.
Performing the mathematical operations of quantities is called quantity calculus. Quantities are multiplied and divided by one another according to the rules of algebra, resulting in new quantities.
The quotient of two quantities, $Q_1$ and $Q_2$, satisfies the relation
$$\begin{align}
\frac{Q_1}{Q_2} &= \frac{ \left\{ Q_1 \right\} \cdot \left[ Q_1 \right] }{ \left\{ Q_2 \right\} \cdot \left[ Q_2 \right] } \\[6pt]
&= \frac{ \left\{ Q_1 \right\} }{ \left\{ Q_2 \right\} } \cdot \frac{ \left[ Q_1 \right] }{ \left[ Q_2 \right] }
\end{align}$$
Thus, the quotient $\left\{ Q_1 \right\}/\left\{ Q_2 \right\}$ is the numerical value $\left\{ Q_1/Q_2 \right\}$ of the quantity $Q_1/Q_2$, and the quotient $\left[ Q_1 \right]/\left[ Q_2 \right]$ is the unit $\left[ Q_1/Q_2 \right]$ of the quantity $Q_1/Q_2$.
For example, assuming a volume of $V = 0.127\ \mathrm{l}$, the density $\rho$ of the above-mentioned sample is
$$\begin{align}
\rho &= \frac{m}{V} \\[6pt]
&= \frac{ 0.100\ \mathrm{kg} }{ 0.127\ \mathrm{l} } \\[6pt]
&= \frac{ 0.100 }{ 0.127 } \cdot \frac{ \mathrm{kg} }{ \mathrm{l} } \\[6pt]
&= 0.79\ \mathrm{kg/l}
\end{align}$$
Similarly, the product of two quantities, $Q_1$ and $Q_2$, satisfies the relation
$$\begin{align}
Q_1 \cdot Q_2 &= \left( \left\{ Q_1 \right\} \cdot \left[ Q_1 \right] \right) \cdot \left( \left\{ Q_2 \right\} \cdot \left[ Q_2 \right] \right) \\[6pt]
&= \left\{ Q_1 \right\}\left\{ Q_2 \right\} \cdot \left[ Q_1 \right] \left[ Q_2 \right]
\end{align}$$
Thus, the product $\left\{ Q_1 \right\}\left\{ Q_2 \right\}$ is the numerical value $\left\{ Q_1Q_2 \right\}$ of the quantity $Q_1Q_2$, and the product $\left[ Q_1 \right]\left[ Q_2 \right]$ is the unit $\left[ Q_1Q_2 \right]$ of the quantity $Q_1Q_2$.
For example, considering the standard acceleration of free fall $g_\mathrm n = 9.80665\ \mathrm{m/s^2}$, the weight $F_\mathrm g$ of the above-mentioned sample is
$$\begin{align}
F_\mathrm g &= m \cdot g_\mathrm n \\[6pt]
&= 0.100\ \mathrm{kg} \times 9.80665\ \frac{\mathrm m}{\mathrm{s^2}} \\[6pt]
&= 0.100 \times 9.80665 \times \mathrm{kg} \cdot \frac{\mathrm m}{\mathrm{s^2}} \\[6pt]
&= 0.98\ \frac{\mathrm {kg\ m}}{\mathrm{s^2}} \\[6pt]
&= 0.98\ \mathrm{N}
\end{align}$$
In forming products and quotients of unit symbols, the normal rules of algebraic multiplication or division apply.
For example, the expansion work $W$ at constant pressure $p = 100\,000\ \mathrm{Pa} = 100\,000\ \mathrm{kg\ m^{-1}\ s^{-2}}$ associated with a volume change of $\Delta V = 0.5\ \mathrm{m^3}$ is
$$\begin{align}
W &= p \cdot \Delta V \\[6pt]
&= 100\,000\ \frac{\mathrm{kg}}{\mathrm{m\ s^{2}}} \times 0.5\ \mathrm{m^3}\\[6pt]
&= 50\,000\ \frac{\mathrm{kg}}{\mathrm{m\ s^{2}}}\cdot\mathrm{m^3}\\[6pt]
&= 50\,000\ \frac{\mathrm{kg\ m^2}}{\mathrm{s^{2}}}\\[6pt]
&= 50\,000\ \mathrm J
\end{align}$$
Two or more quantities cannot be added or subtracted unless they belong to the same kind. The expression shall be written as the sum or difference of expressions for the quantities
$$l=12\ \mathrm m-7\ \mathrm m$$
or parentheses shall be used to combine the numerical values, placing the common unit symbol after the complete numerical value
$$l=\left(12-7\right)\ \mathrm m$$
but it is not permissible to write
$$l=12-7\ \mathrm m\quad\color{red}{\small\text{(wrong!)}}$$
For the same reason, quantities on each side of an equal sign in an equation must be of the same kind
$$\begin{align}
m_\text{total} &= m_1+m_2 \\
1.8\ \mathrm{kg} &= 1.5\ \mathrm{kg}+0.3\ \mathrm{kg}
\end{align}$$
However, quantities of the same kind do not necessarily have the same unit.
$$250\ \mathrm g = 0.250\ \mathrm{kg}$$
$$10\ \mathrm{m/s} = 36\ \mathrm{km/h}$$
Anyway, quantities on each side of an equal sign in an equation must not be of different kinds.
$$1\ \mathrm{mol} = 22.414\ \mathrm l\quad\color{red}{\small\text{(wrong!)}}$$