Guam was ceded to the US by Spain in 1898 .