作者west1996 ()
看板Statistics
标题Re: [程式] SAS配对如何配到最像的1笔资料?
时间Tue Jan 3 18:31:44 2012
※ 引述《FallAugust (八月秋风)》之铭言:
: 以下真的受益匪浅,有一个延伸的问题请教
: 因为有的时候配到最适合的那个对照公司因为资料可得性不能用,
: 这时候就要找第二顺位了,
: 之前我用macro作配对的时候,可以利用排序和 _n_ 的设定
: 留下最相近的五笔资料备用,或者作match-portfolio
: 想请问在sql里面如果想留下最相近的五笔配对资料,应该要怎麽下指令呢?
: 谢谢
分两段跑吧
proc sql;
create table controls_id as
select
one.ID as study_id,
two.ID as control_id,
one.TA as study_TA,
two.TA as control_TA,
one.Sales as study_sales,
two.Sales as control_sales,
one.rand_num as rand_num,
abs(one.ta-two.ta) as diff
from study one, control two
where (two.TA between one.TA*1.1 and one.TA*0.9)
order by one.id, diff;
quit;
data new;
retain flag;
set controls_id;
by study_id;
if first.study_id then flag=0;
flag+1;
if flag<=5;
drop flag;
run;
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.117.131
1F:推 FallAugust:十分感恩! 我终於不用痴痴等回圈了 01/03 20:32