|
地板

楼主 |
发表于 2004-12-13 14:51:22
|
只看该作者
sql(抽样的时候只是按产生的随机数大小而定)
proc sql;
create table temp1 as
select name as name1,sex as sex1,age as age1,height as height1,weight as weight1 from sasuser.class where sex='F';
create table temp2 as
select name as name2,sex as sex2,age as age2,height as height2,weight as weight2 from sasuser.class where sex='M';
run;
proc sql;
create table temp3 as
select a.*,b.*,abs(b.age2 - a.age1) as diff,Normal(100) as rand from temp1 a ,temp2 b;
run;
proc rank data=temp3 out=totaldata;
var rand;
ranks ranknum;
run;
proc sql;
create table temp5 as
select * from totaldata where age1<0;
run;
%macro main;
proc sql noprint;
select count(*) into :num_male from temp1;/*记录男生人数*/
%do i=1 %to &num_male;/*按人数循环*/
proc sql ;
select min(diff) into:mindiff from totaldata;
select max(ranknum) into:maxrand from totaldata where diff=&mindiff;
insert into temp5 select * from totaldata where diff=&mindiff and ranknum =&maxrand;
delete from totaldata where name1 in (select name1 from temp5) or name2 in (select name2 from temp5);
%end;
%mend main;
%main;
说明:数据和使用的变量不同,不过基本做法应该都是一样的,结果文件是temp5 |
|