Yes, but there are limitations on how long you can stay outside Spain without affecting your residency status.