楼主: 颜非如玉
6911 4

[问答] 利用SAS怎么实现 1:N配对抽样的问题 [推广有奖]

  • 1关注
  • 1粉丝

大专生

20%

还不是VIP/贵宾

-

威望
0
论坛币
10 个
通用积分
0
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
449 点
帖子
48
精华
0
在线时间
31 小时
注册时间
2010-10-16
最后登录
2016-6-3

楼主
颜非如玉 发表于 2012-12-21 11:58:44 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
求助各位sas大神~~~假设我有一个数据,9000人的对照,100人的病例,我想运用logist做回归模型分析危险因素,条件logist回归,想以年龄进行匹配,比如年龄相差三岁的可以进行匹配。问题是:如何从9000人中随机选出这100个病例的匹配的对照。想做1:3的匹配。程序如何写?是不是要先分层呢?
资料类型:
y--应变量
age--年龄(匹配因素)
x1--影响因素1
x2--影响因素2
x3--影响因素3

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:logist logis 影响因素 回归模型 危险因素 配对

沙发
jingju11 发表于 2012-12-21 13:25:25
  1. * randomly order the control set;
  2. data control2;
  3. set control;
  4. x = ranuni(1);
  5. proc sort; by x;
  6. run;
  7. * the following set denoted by id for later query;
  8. data control3;
  9. set control2;
  10. id_ctl ++1;
  11. run;
  12. data sampling;
  13. array t[9000] _temporary_;
  14. * load all control age to an array;
  15. if _n_ =1 then do i =1 to nobs;
  16. set control3(keep = age_ctl) nobs =nobs;
  17. t[i] =age_ctl;
  18. end;
  19. set case;
  20. id_case ++1; n = 0;
  21. do id_ctl = 1 to 9000 while(n <3); *jump out when selected 3 controls;
  22. if (t[id_ctl] ^=.) then if (abs(age_case-t[id_ctl]) <= 3) then do;
  23. n ++1; output;
  24. t[id_ctl] =.; * avoid being repeatedly selected;
  25. end;
  26. end;
  27. * in case no control available for a case;
  28. if n = 0 then do;
  29. id_ctl =.; output;
  30. end;
  31. drop age_ctl i n;
  32. run;
  33. proc sql;
  34. create table sampling2 as
  35. select s.*, c.*
  36. from sampling as s left join control3 as c
  37. on s.id_ctl = c.id_ctl
  38. order by s.id_case;
  39. quit;
复制代码
这个程序只是实现最简单的随机条件性选择。程序没有测试。在R编辑器里书写,在sas运行是改变#符号
京剧
This code is tested and works as expected. jngju



藤椅
bobguy 发表于 2012-12-24 09:46:55
jingju11 发表于 2012-12-21 13:25
这个程序只是实现最简单的随机条件性选择。程序没有测试。在R编辑器里书写,在sas运行是改变#符号
京剧
T ...
There is a exist procedure, namely proc surveyselect that can deal with stratify sampling.

Here is an example,

data t1;
   do id=1 to 9100;
      x=ranuni(123);
          flag=0;
          if x<0.5 and cnt<=99 then do;
             flag=1;
                 output;
                 cnt+1;
          end;
          else output;
          
        end;
run;


proc freq data=t1;
table flag;
run;

proc sort data=t1;
by flag;
run;

proc surveyselect data=t1  n=(150 50)
                  seed=4321 out=Sample;
   strata flag;

run;

proc freq data=Sample;
table flag;
run;

板凳
颜非如玉 发表于 2012-12-25 15:12:19
bobguy 发表于 2012-12-24 09:46
There is a exist procedure, namely proc surveyselect that can deal with stratify sampling.

Here ...
运行了下这个程序,倒是运行的出来,这个是成比例分层的程序,好像和我的还不太一样,我在想想呢。在此万分感谢。

报纸
颜非如玉 发表于 2012-12-25 15:13:16
jingju11 发表于 2012-12-21 13:25
这个程序只是实现最简单的随机条件性选择。程序没有测试。在R编辑器里书写,在sas运行是改变#符号
京剧
T ...
这个程序没太看懂,可能是基础实在太差,无可挽救了,不过找了个同学和我一起研究呢。。弄好了在来回复吧。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-28 14:33