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
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.
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
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
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".
Yes. I was thinking about using a retain function but where and how it will go is what i found difficult.
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;
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.