SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 666|回复: 1
打印 上一主题 下一主题

How to creat a subset with two different tests

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2004-9-11 13:24:40 | 只看该作者

How to creat a subset with two different tests

To All:

I have a dataset like this:

id test1 test_date1   test2   test_date2   test3  test_date3
1   ca   2003/02/04   alb     2003/02/04     ca   2003/06/06
2   ca   2003/12/05    ca     2003/12/06    alb   2003/12/06
3   ca   2003/12/05    ca     2003/12/05    alb   2003/12/06
........

(here,test1-test3 denote three tests done on test_date1,
test_date2 and test_date3, repectively.There are two kinds
of tests ("ca" or "alb").I want to create a subset including
all subjects, each of which has both the test "ca" and "alb"
on the same date, e.g., the above subjects with id=1 and id=2
will be included in the dataset. I would appreciate it very
much if anyone could write a SAS program for me to create the
subset.

Thanks a lot!

James Liu
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2004-9-12 14:47:33 | 只看该作者

Try this.

James, I have written a program to solve your problem as following. Hope it can helps.

data test;
length test_date1-test_date3 $10;
input id test1 $ test_date1 $ test2 $ test_date2 $ test3 $ test_date3 $;
datalines;
1 ca 2003/02/04 alb 2003/02/04 ca 2003/06/06
2 ca 2003/12/05 ca 2003/12/06 alb 2003/12/06
3 ca 2003/12/05 ca 2003/12/05 alb 2003/12/06
;
run;
data test1;
  set test;
  array t(3) test1-test3;
  array d(3) test_date1-test_date3;
  del=1;
  do i=1 to 2;
    do j=(i+1) to 3;
      if d[i]=d[j] and ((t[i]='ca' and t[j]='alb') or (t[i]='alb' and t[j]='ca')) then do;
        del=0;
            goto next;
          end;
    end;
  end;
  next:
  if del then delete;
  drop i j;
run;
proc print data=test1;
run;
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-1-11 02:24 , Processed in 3.378525 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表