t*********e 发帖数: 143 | 1 Sas急需帮助
ID RXDATE DRUGDESC DAY_SUPPLY
10001 15DEC2008 ATORVASTATIN 30
10001 14JAN2009 ATORVASTATIN 30
10001 12FEB2009 ATORVASTATIN 30
10003 28FEB2009 SIMVASTATIN 30
10004 28MAR2009 SIMVASTATIN 30
10001 25APR2009 SIMVASTATIN 30
10005 07JUL2009 ATORVASTATIN 30
10005 05AUG2009 ATORVASTATIN 30
10005 03SEP2009 SIMVASTATIN 30
数据里面id是patient id, 现在产生一个table,列出每个patient有没有曾经接受过drugdesc里面2种药品的治疗
最终的结果希望是这样的
ID ATORVASTATIN SIMVASTATIN
10001 1 1
10003 0 1
10004 0 1
10005 1 1
另外也想做一个indicator variable.
对同一个病人,看看他是不是吃atorvastatin的时间早于simvastatin的时间,如果是indicator variable 赋值1, 否则0
请问如何用sas sql达成这个结果 | s******r 发帖数: 1524 | 2 proc sql;
select id, count(distinct DRUGDESC)-1 as drugedesc_ind
from test
where DRUGDESC in ('ATORVASTATIN','SIMVASTATIN')
group by id;
quit;run;
proc sql;
select distinct a.id,
case when a.rxdate < b.rxdate then 1 else 0 end as indx
from test a inner join test b
on a.id=b.id
where a.DRUGDESC='ATORVASTATIN' and b.DRUGDESC='SIMVASTATIN';quit;run;
【在 t*********e 的大作中提到】 : Sas急需帮助 : ID RXDATE DRUGDESC DAY_SUPPLY : 10001 15DEC2008 ATORVASTATIN 30 : 10001 14JAN2009 ATORVASTATIN 30 : 10001 12FEB2009 ATORVASTATIN 30 : 10003 28FEB2009 SIMVASTATIN 30 : 10004 28MAR2009 SIMVASTATIN 30 : 10001 25APR2009 SIMVASTATIN 30 : 10005 07JUL2009 ATORVASTATIN 30 : 10005 05AUG2009 ATORVASTATIN 30
| R*********i 发帖数: 7643 | 3 Why it has to be sql? :-)
Assuming the variable rxdate is a numeric SAS date variable:
proc sql;
select coalesce(a.oldid1,b.oldid2) as id,
min(a.rxdate) as adate format=date9.,
min(b.rxdate) as sdate format=date9.,
(calculated adate>.) as ATORVASTATIN,
(calculated sdate>.) as SIMVASTATIN,
(.
from test(rename=(id=oldid1) where=(drugdesc='ATORVASTATIN')) a full
join
test(rename=(id=oldid2) where=(drugdesc='SIMVASTATIN')) b
on a.oldid1=b.oldid2
group by a.oldid1,b.oldid2
order by id;
quit; |
|