As long as sugar remains sealed and kept from moisture, bugs etc the sugar basically lasts forever.
Sugar when kept sealed in the pantry can last 10 to 20 years and longer.
However once you open a bag of sugar and don't put it in a sealed container to seal it from moisture the sugar may only last a couple years before it starts to get hard.
Even when sugar has gone hard you can still break the sugar up or use something to crush the sugar back up into it's normal form.
Sugar remains safe to use for many years but it's best to put the sugar once opened into a sealed container to keep moisture out of the sugar and to keep it from getting hard.
Keeping the sugar in a sealed container also helps keep bugs out of the sugar such as ants.