The chemical formula gives information regarding the ratio between the atoms and molecules present within the compound. This ratio is given based on moles of the substances and not mass. The ratios can be used to determine the amounts of the constituent elements present in a compound.
You can determine the amount of a particular element present in a compound by converting the mass of the compound to number of moles of compound, and then using the ratio to find the moles of element and then the mass present.
An example of when this is important, is if you are given a compound and asked to find the mass of a particular element, you can do so using the chemical formula.