There might be easier solutions but this works: So I'm first calculating number of product / date. Then I'm generating lower and upper ranges for values then I'm generating random number for each observation and then joining observations with missing price with this random number. data one; input subject date product price; datalines; 1 1 1 100 1 1 2 . 2 1 1 . 2 1 2 120 3 1 1 110 3 1 2 . 4 1 1 . 4 1 2 130 5 1 1 90 5 1 2 . 6 1 1 . 6 1 2 80 7 2 1 . 7 2 2 140 8 2 1 120 8 2 2 . 9 2 1 . 9 2 2 100 10 2 1 . 10 2 2 70 11 2 1 80 11 2 2 . 12 2 1 150 12 2 2 . ; run; data product_date; set one(keep=date product price where=(price ne .)); proc sort; by date product price; run; proc sql; create table P_D_CNTS as select date, product, count(price) as count from product_date group by date, product; quit; proc sql; create table PD2 as select pd.date, pd.product, pd.price, cnts.count from product_date pd, P_D_CNTS cnts where pd.date = cnts.date and pd.product = cnts.product; quit; data PD3; set Pd2; by date product price; retain lower upper 0; if first.product then do; lower = 0; upper = 1/count; end; else do; lower = lower + 1/count; upper = upper + 1/count; end; run; data two; set one; random=rand('uniform'); run; proc sql; create table want as select two.subject, two.date, two.product, two.price from two where price ne . union select two.subject, two.date, two.product, PD3.price from two, PD3 where two.date = PD3.date and two.product = pd3.product and two.random between pd3.lower and pd3.upper and two.price eq .; quit;
... View more