overlapping date observations

Solved
Occasional Contributor
Posts: 6

overlapping date observations

I've got dates describing periodes (start end) and a variable describing waiting time (wt). However, the dates are partialle overlapping. This is nearly fixed in the attached program but I would like to have latest observation of wt to be placed in correctly. Anyone?

Accepted Solutions
Solution
‎01-05-2017 12:06 PM
Contributor
Posts: 24

Re: overlapping date observations

[ Edited ]

Hi.

If I got this right, you just need to sort the data correctly and fetch the previous stdate between by groups.

* sort reversing stdate (recent to later);
proc sort data=waits;
by hospid diag descending stdate;

run;

* adjust overlapping between by groups;
data waits2;
set waits;
format stdate enddate date9.;
drop _:;
by hospid diag;

* fetch previous stdate;
_enddate=lag1(stdate);
* skip first by group row, fix overlapping;
if not first.diag then enddate=min(enddate,_enddate-1);

run;

* sort back (later to recent);
proc sort;
by hospid diag stdate;
run

lagN functions will retrieve the previous Nth row value of PDV.

The rest is just pure data step logic.

Hope it helps.

Daniel Santos @ www.cgd.pt

All Replies
Posts: 1,837

Re: overlapping date observations

You have similar situation as in next post.See solution - it fits your case:

Solution
‎01-05-2017 12:06 PM
Contributor
Posts: 24

Re: overlapping date observations

[ Edited ]

Hi.

If I got this right, you just need to sort the data correctly and fetch the previous stdate between by groups.

* sort reversing stdate (recent to later);
proc sort data=waits;
by hospid diag descending stdate;

run;

* adjust overlapping between by groups;
data waits2;
set waits;
format stdate enddate date9.;
drop _:;
by hospid diag;

* fetch previous stdate;
_enddate=lag1(stdate);
* skip first by group row, fix overlapping;
if not first.diag then enddate=min(enddate,_enddate-1);

run;

* sort back (later to recent);
proc sort;
by hospid diag stdate;
run

lagN functions will retrieve the previous Nth row value of PDV.

The rest is just pure data step logic.

Hope it helps.

Daniel Santos @ www.cgd.pt

Occasional Contributor
Posts: 6