全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1596 4
2010-09-20
在我的数据库中有20000多的case,是由不同年级不同班级的学生组成,这其中有200个病例,如果我要在相同班级,选择同年龄同性别的学生作为对照。在sas中如何编程实现?假设性别变量名为sex,年龄为age,班级为class。请大家帮我。谢谢
二维码

扫码加我 拉你入群

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

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

全部回复
2010-9-21 08:24:34
是不是我没表达清楚?还是sas真的做不了?请人指点啊。
二维码

扫码加我 拉你入群

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

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

2010-9-21 08:58:02
不知道理解正确不?
data a;
input class @@;
cards;
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4
;
run;
data b;
set a;
set sashelp.class;
run;
proc sort data=b;
by class sex age;
run;
data b;
set b;
by class sex age;
if not( first.age=1 and last.age=1);
run;
二维码

扫码加我 拉你入群

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

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

2010-9-21 10:31:43
data temp;
input id $ class sex $ age case_flg;
cards;
001 1 F 14 0
002 1 M 15 0
003 1 F 14 1
004 1 F 13 0
005 1 M 15 1
006 1 M 15 0
007 1 F 14 0
008 1 M 16 0
009 1 M 16 0
010 1 F 14 0
011 2 M 15 1
012 2 M 15 0
013 2 F 14 0
014 2 F 13 0
015 2 M 15 0
016 2 M 15 0
017 2 F 14 0
018 2 M 14 0
019 2 M 15 0
;
proc sql;
    create table aim as
    select *,ranuni(0) as random
          from temp
    where catx("_",class,sex,age) in
                      (select distinct catx("_",class, sex,age)
                             from temp
                                where case_flg=1)
          group by class,sex,age,case_flg
          having random=max(random)
          order by class,sex,age,case_flg;
quit;

上面代码仅适用于每个class+sex+age 组合只有1个case,希望能对你有点帮助。
二维码

扫码加我 拉你入群

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

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

2010-9-21 12:40:12
好久没来了
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群