The three-loop β function in SU(N) lattice gauge theories