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

Hey all,

 

I'm attempting to create a variable that "flags" patients that visited hospital within 30 days of being admitted as an inpatient. I'm not comfortable uploading any data (bcuz HIPAA) but i'll try to explain the dataset to the best of my ability. 

 

Basically, there's an admission date "adm_date" and discharge data "dsch_date" for every record within the dataset. Each patient visit to the hospital is a new row of the file. I am using the code below but the computer will calculate "gap" between every row whereas I need the computer to only calculate "gap" if the prior visit was an inpatient stay ("IP"). I ONLY need to know the gap, and therefore whether or not they were here again, if the prior visit was IP but the visit after can be anything else. The variable with IP in it also has outpatient (OP), observation (OB), and emergency (ED) as its levels. I tried adding an if-then statement in front of the line that created the gap variable but that seems to have told it only to calculate gap if IP is present, resulting in it calculating the gap of the visit prior to the IP stay instead of the one after. 

 

Data encounters_final1;
set encounters_final;
By corp_id;
Ref_date = LAG(Dsch_date);
Format Ref_date YYMMDD10.;
Label Ref_date = "Reference Date";
Gap = Adm_date - Ref_date;

IF first.corp_id then do;
Ref_date = .;
Gap= .;
Tag =.;
Readmissions =.;
End;
If 0 <= Gap <= 30 then Tag=1;
Readmissions + Tag;
Run;

 

I did a little bit of research and saw that maybe I could use an array for this? Any advice is appreciated. 

1 ACCEPTED SOLUTION

Accepted Solutions
supp
Pyrite | Level 9

Not sure if I understand the ask. If you only want to calculate the gap when the prior visit was IP maybe you can do something like:

 

prior_visit_type = lag(visit_type);
if prior_visit_type = 'IP' then do;
    ref_date = lag(dsch_date);
end;

etc....

View solution in original post

2 REPLIES 2
supp
Pyrite | Level 9

Not sure if I understand the ask. If you only want to calculate the gap when the prior visit was IP maybe you can do something like:

 

prior_visit_type = lag(visit_type);
if prior_visit_type = 'IP' then do;
    ref_date = lag(dsch_date);
end;

etc....
amail94
Fluorite | Level 6

Hadn't even thought to just use the lag function again to find the last visit type. Ended up changing the line creating the gap code to this and now we're good! 

 

if LAG(pat_class)='IP' then Gap = Adm_date - Ref_date;

 

Thank you

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
  • 2 replies
  • 518 views
  • 0 likes
  • 2 in conversation