I importing many excel files with long variables names and lots of space. The truncated variable names do not work my purposes. So I need to shorten the labels into workable variable names.

I have gotten this code to work until the rename step, but I am not seeing the (probably very obvious error) in the rename step.

clear
set obs 2
gen ShelteredESHomelessPeoplein = 1
label variable ShelteredESHomelessPeoplein "Sheltered ES Homeless People in Families, 2007"
foreach v of varlist _all {
di "`v'"
local wholename : variable label `v'
di "`wholename'"
local new = substr(subinstr("`wholename'", " ", "",.),1,30)
di "`new'"
di "`v'" " " "`new'"
rename "`v'" " " "`new'"
}

Thanks in advance