我有这样的数据集:
DATA HAVE;
INPUT _USUBJID $ VISITNUM $ VISIT $ ;
CARDS;
01/01 VISIT1 SCREENING
01/01 VISIT1 SCREENING
01/01 VISIT1 SCREENING
01/01 VISIT1 RETEST
01/01 VISIT1 RETEST
01/01 VISIT3 BASELINE2
01/01 VISIT3 BASELINE2
01/01 VISIT3 RETEST
01/01 VISIT3 RETEST
01/02 VISIT1 SCREENING
01/02 VISIT1 SCREENING
01/02 VISIT3 BASELINE2
01/02 VISIT3 BASELINE2
;
RUN;
我需要将其重组为:
DATA WANT;
INPUT _USUBJID $ VISITNUM $ VISIT $ ;
CARDS;
01/01 VISIT1 RETEST
01/01 VISIT1 RETEST
01/01 VISIT3 RETEST
01/01 VISIT3 RETEST
01/02 VISIT1 SCREENING
01/02 VISIT1 SCREENING
01/02 VISIT3 BASELINE2
01/02 VISIT3 BASELINE2
;
RUN;
如果主题同时具有SCREENING和RETEST值,我需要提取该主题的RETEST值。如果一个主题没有任何RETEST值,那么我只需要访问(即本例中的SCREENING或BASELINE2)。
答案 0 :(得分:0)
我会分三个阶段来完成:
SQL中的示例:
proc sql;
create table retest as
select *
from have
where VISIT="RETEST";
create table onetest as
select * from
((select distinct _usubjid, visitnum
from have)
except
(select distinct _usubjid, visitnum
from retest)) as onetesters
left join
have on
onetesters._usubjid = have._usubjid and
onetesters.visitnum = have.visitnum;
create table want as
select * from retest
union all
select * from onetest;
quit;