One can use a 1-(DATA STEP) solution. First, some simulated data; Second, a proposed 1-(DATA STEP) solution. Here, one wants to chose the minimum of (10, (# unique id)) = zSize = min(10,zId); One can use some number other than 10. /*****************************/ /**** some simulated data ****/ /*****************************/ data t_a; do id = 100 to 120; do store_id = 'A','B','C','D'; Sales = ceil(500*ranuni(3)); output; end; end; run; /*****************************/ /**** a proposed solution ****/ /*****************************/ data t_b(keep=id store_id Sales); do until(zDone); set t_a(keep=id) end=zDone; by id; if first.id then zId+1; end; zSize = min(10,zId); do until(xDone); set t_a end=xDone; by id; if first.id then do; r1= ceil(zId*ranuni(3)); if (r1 <= zSize) then do; zOutput=1; zId+(-1); zSize+(-1); end; else do; zOutput=0; zId+(-1); end; end; if (zOutput=1) then output; end; run;
... View more