PG: Your observation to replace the lower boundary of the array to 0 is correct. The program works if the array starts with 0-index for your example. On practical consideration, such a situation may not arise. Look at the subgroup: subject = 13, date = 3 and product = 1. It is a lone observation with a missing price value. In this case, my COUNT which counts the non-missing price-values in the subset, is zero. This results in imputing a missing value by another missing value -- helped by 0-index. So, either I change to 0-start or add a condition to check that there is at least one nonmissing price value in a subgroup before doing the imputation -- in that case there is no need to change the array index. For the benefit of the Original Poster, I place the revised program here: data want; array k[10] _temporary_; count = 0; do until(last.product); set have ; by date product; if not missing(price) then do; count + 1; k[count] = price; end; end; do until(last.product); set have; by date product; if price = . and count then do; i = ceil(ranuni(123) * count); price = k; end; output; end; drop i count; run; ------------- DataSP
... View more