- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello programmers,
I am working on an ER injury data.
I consider an injury as 'new' if there were no previous ER visits with an injury within 90 days. Otherwise, it’s a 'followup' visit. All patients are injury free prior to 1998. The data is also such that a non-injury visit cannot occur between two related injury visits.
I have been struggling to Mark each injury as being "new" or "followup" and I've also struggled with using an If statement to subset only those records that reflect a new injury.
Any help is appreciated. Is it possible to use a lag and first. for this? My dataset is attached.
Thanks
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First would be used to reset statistics/counters, but RETAIN will be a key here. You will also use LAG to get the previous value to test if it's within 90 days, assuming you sort it correctly. But what happens if you have a visit on day 1, day 89 and day 100? Would Day 100 be a follow up or new visit?
It would help if you could provide a smaller example data set directly here and show your expected output as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
First would be used to reset statistics/counters, but RETAIN will be a key here. You will also use LAG to get the previous value to test if it's within 90 days, assuming you sort it correctly. But what happens if you have a visit on day 1, day 89 and day 100? Would Day 100 be a follow up or new visit?
It would help if you could provide a smaller example data set directly here and show your expected output as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data Analysis;
set ERTeachinghosp;
by id;
laginjury = lag(injury);
if not first.id then PrevInjury = laginjury;
drop laginjury;
run;
proc print; run;
data Analysis2;
set Analysis;
if lag(visitdate)- visitdate = 90 then laginjury = 'new';
else laginjury = 'Follow-up';
run;
proc print; run;
I want to
1. subset my injuries : (an injury is new if there were no previous visits with an injury within 90 days..otherwise it's a follow up)
2. Be able to mark each injury as being "new" or "follow up".
I ran this code and it showed me that all my cases are follow-ups.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
But what happens if you have a visit on day 1, day 89 and day 100? Would Day 100 be a follow up or new visit?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Jan 31st = Day 31 = follow up
March 15 = Day 70 (approx) = follow up
April 8th = Day 100 (approx) = follow up or new??
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Here's what i'm trying to do
I have provided 3 scenarios
observation 1:
Visit =1 (day 1) , Injury =Yes, Injury= New
Visit=2, Injury= No; follow up
Visit=3, injury= No; follow up
Visit=4, injury=No; follow up
Visit=5 injury=No; follow up
Observation 2;
Visit =1(Day1) , Injury =Yes, Injury= New
Visit=2, Injury=No; follow up
Visit=3, injury=No; follow up
Visit=4 (Day 100) , injury= Yes, Injury= New
Visit=5 injury=No; follow up
observation 3;
Visit =1 (day 1) , Injury =Yes, Injury= New
Visit=2, Injury=No ; follow up
Visit=3 (day 70), injury=Yes; Injury= 'follow up"
Visit=4, injury=No; follow up
Visit=5 injury=No; follow up
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm asking about this situation, which will occur:
observation 3;
Visit =1 (day 1) , Injury =Yes, Injury= New
Visit=2, Injury=No ; follow up
Visit=3 (day 70), injury=Yes; Injury= 'follow up"
Visit=4, (day 100) injury=Yes; Injury = "Follow up" or "new"
Visit=5 injury=No; follow up
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
It would be NEW. Because the patient is presenting after 90 days (day 100) with Injury. Injury is coded as 1= yes, 0=No.
If the patient however presented on day 70 with injury(injury=1), it would not be new but a "follow up".
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes. I was thinking about using a retain function but where and how it will go is what i found difficult.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You're only setting it on each new injury then.
data want;
set have;
by id date;
retain prev_inj_date;length type $20.;
if first.id then call missing(prev_inj_date);
if injury = 1 and missing(prev_inj_date) then prev_inj_date = date;
if injury = 0 then type='follow up';
if injury =1 and date - prev_inj_date <90 then type = 'follow up';
else do;
type = 'New';
prev_inj_date = date;
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What does the injury 0/1 values stand for in the data set?
And those are what type of dates? They look like date time but are all in 1960 so I'm guessing those are off for some reason?
Not sure what they reflect.
Your code isn't far off, so this is my last answer here, which assumes visit is your visit date. This also assumes any previous visit within 90 days is the same from the last visit, not the original visit.
data want;
set have;
by id;
length type $20.;
prev_visit = lag(visit);
if first.id then call missing(prev_visit);
if visit - prev_visit <= 90 then type='Follow Up';
else type = 'New';
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content