From: VG on
Hello,

I have a problem where i have a popuation taking drugs and there are
multiple start and stop dates for each drug. I need to create a any
drug use start and stop date,

drg1_stdt1 = 1/1/2010, drg1_enddt1=2/1/2010, drg2_stdt1=1/15/2010,
drg2_stdt1=2/15/2010'

For above scenario i would have a anyuse_stdt1=1/1/2010 and
anyuse_enddt1=2/15/2010. The second start date for anyuse
(anyuse_stdt2) would look at all the start dates in all five drugs and
pick the stdt closest to anyuse_enddt1

Since the above drugs have multiple start and stop dates, I would end
up with multiple start and stop dates for anyuse as well.

drg1 for example could have 5 start and stop dates,
drg1_stdt1 - drg1_stdt5, drg1_enddt1 - drg1_enddt5

I was thinking in terms of a multidimentional array, but I am finding
it difficult to conceptualize. Any help with this would be greatly
appreciated.

From: Reeza on
On Aug 11, 11:55 am, VG <vamshidarg...(a)gmail.com> wrote:
> Hello,
>
> I have a problem where i have a popuation taking  drugs and there are
> multiple start and stop dates for each drug. I need to create a any
> drug use start and stop date,
>
> drg1_stdt1 = 1/1/2010, drg1_enddt1=2/1/2010, drg2_stdt1=1/15/2010,
> drg2_stdt1=2/15/2010'
>
> For above scenario i would have a anyuse_stdt1=1/1/2010 and
> anyuse_enddt1=2/15/2010. The second start date for anyuse
> (anyuse_stdt2) would look at all the start dates in all five drugs and
> pick the stdt closest to anyuse_enddt1
>
> Since the above drugs have multiple start and stop dates, I would end
> up with multiple start and stop dates for anyuse as well.
>
> drg1 for example could have 5 start and stop dates,
> drg1_stdt1 - drg1_stdt5, drg1_enddt1 - drg1_enddt5
>
> I was thinking in terms of a multidimentional array, but I am finding
> it difficult to conceptualize. Any help with this would be greatly
> appreciated.

What's your data currently like right now?
From: VG on
Hi Reeza

THe data was single record per individual. I was overthinking it by
putting all the start stop dates in one line. I found something that
Ian Whitlock had written to handle this issue which required me to
transpose the data to multiple records per individual with each line
containing one start and stop date. Code below is from Ian posted in
the uga listserv

data q ( keep = id curstart curend ) ;
retain curstart curend ;
format curstart curend startdate enddate date9. ;
set w ;
by id ;
if first.id then
do ;
curstart = startdate ;
curend = enddate ;
end ;

if enddate < startdate then error ;

if enddate > curend
and curstart <= startdate <= curend + 1 then
curend = enddate ;

if startdate > curend then
do ;
output ;
curstart = startdate ;
curend = enddate ;
end ;

if last.id then
do ;
output ;
end ;
run ;

From: data _null_; on
On Aug 12, 8:57 am, VG <vamshidarg...(a)gmail.com> wrote:
> Hi Reeza
>
> THe data was single record per individual. I was overthinking it by
> putting all the start stop dates in one line. I found something that
> Ian Whitlock had written to handle this issue which required me to
> transpose the data to multiple records per individual with each line
> containing one start and stop date. Code below is from Ian posted in
> the uga listserv
>
> data q ( keep = id curstart curend ) ;
>    retain curstart curend ;
>    format curstart curend startdate enddate date9. ;
>    set w ;
>    by id ;
>    if first.id then
>    do ;
>       curstart = startdate ;
>       curend = enddate ;
>    end ;
>
>    if enddate < startdate then error ;
>
>    if enddate > curend
>       and curstart <= startdate <= curend + 1 then
>       curend = enddate ;
>
>    if startdate > curend then
>    do ;
>       output ;
>       curstart = startdate ;
>       curend = enddate ;
>    end ;
>
>    if last.id then
>    do ;
>       output ;
>    end ;
> run ;

Show example of data you start with that represents all scenarios.
Then show example of the data arrangement you want to end up with.
Details.