问题1:没有完全理解,暂时把前两个如果看作是没有不同出院日期的人,后两个看作有不同出院日期的人,可能没包括所有的情况,请楼主先试一下:
- data test;
- input name $ caseid $ surdate : $10. surname $ outdate : $10.;
- cards;
- XW 01 2012-11-2 xx 2012-11-7
- XL 02 2012-11-2 xy 2012-11-8
- XL 02 2012-11-2 xy 2012-11-8
- XH 03 2012-11-2 xx 2012-11-9
- XH 03 2012-11-6 xy 2012-11-9
- XH 03 2012-11-7 xa 2012-11-18
- XH 03 2012-11-11 xz 2012-11-18
- ;
- * choose subjects who have different discharge dates;
- proc sql;
- create table dupdate as
- select distinct name
- from test
- group by name
- having count(distinct outdate)>1;
- quit;
- * condition 1;
- proc sql;
- create table cond1 as
- select *, 0 as bktime
- from test
- where name not in (select name from dupdate)
- group by name,caseid
- having count(*)=1 and surdate<=outdate;
- quit;
- * meet condition 2 and have the same surgery name;
- proc sql;
- create table cond2_1 as
- select *, 1 as bktime, 1 as surtime
- from test
- where name not in (select name from dupdate)
- group by name,caseid
- having count(*)>=2 and count(distinct surname)=1 and surdate<=outdate;
- quit;
- * meet condition 2 and do not having the same surgery name;
- proc sql;
- create table cond2_2 as
- select *, 1 as bktime
- from test
- where name not in (select name from dupdate)
- group by name, caseid
- having count(*)>=2 and count(distinct surname)>1 and surdate<=outdate;
- quit;
- * condition 3;
- proc sql;
- create table cond3 as
- select *, 2 as bktime
- from test
- where name in (select name from dupdate)
- group by name, caseid, outdate
- having count(*)>=2 and surdate<=outdate;
- quit;
- * condition4;
- proc sql;
- create table cond4 as
- select *, 1 as bktime
- from test
- where name in (select name from dupdate)
- group by name, caseid, outdate
- having count(*)=1 and surdate<=outdate;
- quit;
- data combine;
- set cond1 cond2_1 cond2_2 cond3 cond4;
- run;
复制代码
问题2:“挑选出出院日期完全相同的病人” 应该怎么理解?病案号03有两个不同的出院日期
问题3: 楼主需要转置后得到什么样的格式,可否举个例子?
问题4: 是这个意思吗?
data test1;
set test;
date1=input(surdate,yymmdd10.);
date2=input(outdate,yymmdd10.);
format date1 date2 yymmdd10.;
keep surdate outdate date1 date2;
run;