Firstly, the assumption in these problems is that you have a 100g sample.
Sulfur = 31.42 g
Oxygen = 31.35 g
Fluorine = 37.23 g
Then, these values are converted to moles by multiplying by the ratio of 1 mole divided by the molar mass of the element.
Sulfur:
31.42 g * 1mol/32.06 u = 0.98 mol Sulfur
Oxygen:
31.35 g * 1mol/15.999u = 1.96 mol Oxygen
Fluorine:
37.23 g * 1mol/18.998u= 1.96 mol Fluorine
Rounding these numbers, you have 1 mole of Sulfur, 2 moles of Oxygen, and 2 moles of Fluorine, and so the empirical formula is
SO2F2