|
|
8#

楼主 |
发表于 2010-2-25 10:55:54
|
只看该作者
Re: 请教诸位:
I wish this simplified approach helps (or at least addresses the problem at all). The output may be refined to meet the requirement more specific. E.g., some rows in the output can be further combined with duplicated items removed, etc., if desired. <!-- s:-) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":-)" title="Smile" /><!-- s:-) -->
[code:2h9ay8o8]proc sql;
create table myData as
select *,
monotonic() as rowID
from myData
order by id,
start,
stop,
drug;
quit;
proc sql;
create table semi_final as
select a.id,
max(a.start, b.start, c.start) as start,
min(a.stop, b.stop, c.stop) as stop,
trim(a.drug) || '/' || trim(b.drug) || '/' || trim(c.drug) as drugs
from myData as a,
myData as b,
myData as c
where a.rowID < b.rowID < c.rowID and
a.id = b.id = c.id and
a.drug ^= b.drug and b.drug ^= c.drug and a.drug ^= c.drug and
max(a.start, b.start, c.start) <= min(a.stop, b.stop, c.stop)
order by a.id,
calculated start,
calculated stop,
calculated drugs;
quit;
data final(drop = drugs i
rename = (final_drugs = drugs)
);
set semi_final;
by id
start
stop
drugs;
retain final_drugs;
length final_drugs $200;
if first.stop then final_drugs = drugs;
do i = 1 to 3;
if index(final_drugs, strip(scan(drugs, i, '/'))) = 0 then final_drugs = strip(final_drugs) || '/' || strip(scan(drugs, i, '/'));
end;
if last.stop then output;
run;[/code:2h9ay8o8] |
|