It looks like you're trying to determine the amount of memory used by your hash tables.
If so, then the code you wrote is along the right idea. You just have some problems with syntax and structure.
Here's the one I wrote, and tested, and it appears to be correct based upon the data in my hash tables
alias hash_size {
var %a = $hget(0)
while %a {
var %c = $hget(%a), %d = $hget(%c,0).item
while %d {
var %e = $hget(%c,%d).item, %f = $hget(%c,%d).data
inc %g $calc($len(%e) + $len(%f))
dec %d
}
dec %a
}
echo -a $bytes(%g).suf
}