BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ChuksManuel
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Can you show what you've tried so far?

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.

View solution in original post

13 REPLIES 13
Reeza
Super User
Can you show what you've tried so far?

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.
ChuksManuel
Pyrite | Level 9

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.

 

 

Reeza
Super User
And this situation:
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?
ChuksManuel
Pyrite | Level 9
If the person presents to the ER 90 days after their last visit with an injury, then the injury is new.
So a visit on day 100 (with an injury) would be "new" assuming the patient visited on day 1.
Reeza
Super User
Jan 1st = Day 1 = injury
Jan 31st = Day 31 = follow up
March 15 = Day 70 (approx) = follow up
April 8th = Day 100 (approx) = follow up or new??
ChuksManuel
Pyrite | Level 9

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

 

Reeza
Super User

 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

 

ChuksManuel
Pyrite | Level 9

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".

 

 

Reeza
Super User
Ok, then the code I provided will not work, because you need to retain the date of the first injury.
ChuksManuel
Pyrite | Level 9

Yes. I was thinking about using a retain function but where and how it will go is what i found difficult.

Reeza
Super User

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;

Reeza
Super User

 

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;
ChuksManuel
Pyrite | Level 9
Thank you. It worked!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 2552 views
  • 0 likes
  • 2 in conversation