I think the issue is with this line
x[4] = Char( arra[binxx[j]] );
I would modify the loop to loop over the rows instead of associative array + rows:
Names Default To Here(1);
dt = Current Data Table();
/// Get list of all the bins
binxx = Associative Array(:Bins[23 :: N Rows(dt)]) << Get Keys;
delcols = {"", " ", "}"};
/// Remove garbage values
For(i = 1, i <= N Items(delcols), i++,
Remove From(binxx, As List(Loc(binxx, delcols[i])));
);
///Get rows where Bins column contains BIN =
rows = dt << get rows where(Contains(:Bins, "BIN = "));
total = {};
//Loop to calculate the count of each bins
For(i = 1, i <= N Items(binxx), i++,
Insert Into(total, N Items(dt << get rows where(:Bins == binxx[i])))
);
//create array to store bin and counts
arra = Associative Array(binxx, total);
//loop to modify the character count in the table
For(i = 1, i <= N Items(rows), i++,
x = Words(:Bins[rows[i]]);
curbin = Substitute(x[3], "\!"", "");
If(Contains(arra, curbin),
x[4] = Char(arra[curbin]);
:Bins[rows[i]] = Concat Items(x);
,
continue();
);
);
-Jarmo