The student visa in Scotland is valid so long as your education in an approved university in Scotland is still active. If you have to spend more years than expected, you need to apply to extend your student visa in Scotland.