I guess it is working, but mayhap it does not do what you expect. You can have multiple BEGIN and/or multiple END patterns in awk (although maybe not all implementations), but they ARE executed at the begin or the end of the entire programme. So - if you need the single elements and the average, in parallel to calculating the avg, put the elemants into an array, and then, in the END action, do your summ calculation looping through the array, and then the rest of your calculations.
If I want to find the sum of the square value of all elements in an array,
would that be
summm+=arr[i^2]
The problem I am trying to find a variance, using var(X)=<X^2>-<X>^2
and I am getting a negative value (wrong, var>0 ALWAYS). So I suspect
my procedure is wrong.