标题: How to creat a subset with two different tests [打印本页] 作者: shiyiming 时间: 2004-9-11 13:24 标题: 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作者: shiyiming 时间: 2004-9-12 14:47 标题: 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;