New figures show 18,278 Scots waited more than 12 weeks for inpatient or day case treatment in the three months to the end of September.