楼主: Michael1941
1620 4

如何选择对照? [推广有奖]

  • 0关注
  • 1粉丝

已卖:61份资源

硕士生

57%

还不是VIP/贵宾

-

威望
0
论坛币
1087 个
通用积分
2.9700
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
960 点
帖子
73
精华
0
在线时间
222 小时
注册时间
2009-2-28
最后登录
2023-4-19

楼主
Michael1941 发表于 2010-9-20 20:09:17 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
在我的数据库中有20000多的case,是由不同年级不同班级的学生组成,这其中有200个病例,如果我要在相同班级,选择同年龄同性别的学生作为对照。在sas中如何编程实现?假设性别变量名为sex,年龄为age,班级为class。请大家帮我。谢谢
二维码

扫码加我 拉你入群

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

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

关键词:Case 数据库 Age CAS SEX 选择

回帖推荐

pobel 发表于4楼  查看完整内容

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 ...

本帖被以下文库推荐

沙发
Michael1941 发表于 2010-9-21 08:24:34
是不是我没表达清楚?还是sas真的做不了?请人指点啊。

藤椅
823954913 发表于 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;

板凳
pobel 在职认证  发表于 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,希望能对你有点帮助。
已有 1 人评分学术水平 热心指数 收起 理由
crackman + 1 + 5 又来了

总评分: 学术水平 + 1  热心指数 + 5   查看全部评分

和谐拯救危机

报纸
crackman 发表于 2010-9-21 12:40:12
好久没来了

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

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