|
|
沙发

楼主 |
发表于 2009-2-19 00:36:06
|
只看该作者
Re: 如何在队列内 为病例随机选对照???
[code:349h2k4g]data ahuige;/*pseudo dataset*/
cancer=0;
do code=1 to 70000;
if code<=300 then cancer=1;
else cancer=0;
age=ceil(uniform(34938493)*100);
output;
end;
run;
data ahuigeAddId;
set ahuige;
randomid=normal(43578437); /*change to 0 to get unrepeatable random id*/
lowage=age-2;
upage=age+2;
run;
proc sort data=ahuigeAddId;
by randomid;
run;
data cancer noncancer;
set ahuigeADDid;
if cancer=1 then output cancer;
else output noncancer;
;
run;
%macro getPeers(code,low,up);
data candidate(keep=patientId code age ) noncancer(drop=patientid n);
set noncancer;
patientId=&code;
if &low<=age<=&up then
do;
n+1;
if n<=4 then output candidate;
else output noncancer;
end;
else output noncancer;
run;
proc datasets;
append base=final
data=candidate;
run;
%mend;
option nomprint;
proc datasets lib=work;
delete final;
run;
data _null_;
set cancer;
length cmd $200;
cmd='%getpeers('||code||','||age-2||','||age+2||')';
call execute(cmd);
run;[/code:349h2k4g] |
|