This is a version of syntax Replace values higher than n by the mean of the other values, adapted to capabilities of modern SPSS versions (tested with IBM SPSS Statistics 24). Code is much simpler as we don't need anymore to store aggregated values to external file and match it with original data. 

Check it out