HI @novinosrin ,
Thank you for your reply and I have been trying on your code and making small changes to make it work for me but the code doesn't seem to work my actual data. I donot understand why.
Here is the raw data which is de-identified
data have;
input PID StartDate :anydtdte. Drug $;
format startDate yymmdd10.;
datalines;
1 10MAY2012 arb
1 10MAY2012 acl
1 17MAY2012 arb
1 17MAY2012 acl
1 30MAY2012 rlo
1 30MAY2012 rlo
1 30MAY2012 rlo
1 26JUN2012 rlo
1 19JUL2012 rlo
1 27AUG2012 rlo
1 25SEP2012 rlo
2 19FEB2008 eva
2 19FEB2008 eva
2 19FEB2008 arb
2 19FEB2008 arb
2 19FEB2008 emc
2 28FEB2010 ymc
3 09NOV2011 isp
3 27NOV2011 emc
;
run;
proc sort data=have;
by PID Startdate Drug;
run;
proc sql;
select count(distinct Drug) into : reg_limit TRIMMED from have;
quit;
%put ®_limit;
data want2;
if _N_=1 then
do;
if 0 then
set have;
declare hash h(dataset: "have", multidata: 'y');
h.defineKey('pid');
h.defineData('StartDate', 'drug');
h.defineDone();
end;
length _t $500;
set have(rename=(startdate=_startdate drug=_drug));
by pid;
array t(*) $100 Line1-Line®_limit;
retain _t t;
if first.pid then
do;
call missing(of t(*), _t);
_count=0;
_count+1;
t(_count)=_drug;
_n=0;
do while(h.do_over(key: pid) eq 0);
k=intck('day', _startdate, startdate);
if k<=10 and drug ne _drug then
f=1;
else
f=0;
if f=1 then
do;
_n+1;
if _n=1 then
t(_count)=catx('+', _drug, drug);
else if countc(strip(_t), strip(drug))=0 then
t(_count)=catx('+', t(_count), drug);
end;
_t=cats(of t(*));
*output;
end;
_t=cats(of t(*));
end;
else
do;
check=countc(strip(_t), strip(_drug));
if countc(strip(_t), strip(_drug))=0 then
do;
_count+1;
t(_count)=_drug;
do while(h.do_over(key: pid) eq 0);
if intnx('day', _startdate, -3)<=startdate<=intnx('day', _startdate, 10)
and drug ne _drug then
t(_count)=catx('+', t(_count), drug);
_t=cats(of t(*));
*output;
end;
end;
end;
if last.pid then
output;
keep pid Line:;
run;
/////***********************************************************//////
This data doesn't seem to yield the same result as expected from the model dataset I have posted before. Can you let me know why is that happening.
If you observe the below output I renamed Reg to line. The drug rlo is not coming up under line2/reg2 for PID 1 ans same goes for PID 2
This is the output I get is below:
Please suggest.
... View more