/*假设需要随机抽取的组数为n*/
%let n=2;
proc sql noprint;
create table temp1 as select distinct code, RANUNI(0) as _ran_ from x order by _ran_;
create table temp2 as select * from temp1 (obs=&n);
create table final as select * from x where exists (select * from temp2 where x.code=temp2.code);quit;