BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi

I need some help with my sas coding. I have a dataset with admissions to hospitals, where each admission is registered as one observation. That means that one person can appear in the dataset more than once and some people have up to a 100 admissions. We can order the dataset so that all admissions that belongs to one person is numbered and ordered by the admission date.

If a person has had an admission on date x, we would now like to delete any following admissions(observations) that appear within 4 days after date x. Do any you know an easy way to do this?

Thanks Susan
8 REPLIES 8
deleted_user
Not applicable
Susan,

You'll have to confirm that this handles things (cases) as you want, but it should at least get you started (assumes that your data has been sorted). Note what happens with patient number 4 (where I reset the "base" date), and what happens with patient 1 where 16FEB09 is NOT deleted --- I'm not sure if this is what you'd want to happen. If you'd want 16FEB09 deleted in a case like this (where 15FEB09 was already deleted), then the code would have to be revised.

data test;
informat admitted date7.;
format admitted date7.;
input patid admitted;
cards;
1 11FEB09
1 15FEB09
1 16FEB09
2 10FEB09
2 17FEB09
3 20FEB09
4 05MAR09
4 11MAR09
4 12MAR09
;
run;

data subset;
retain compare_date;
format compare_date date7.;
set test;
by patid admitted;

if first.patid then do;
compare_date = admitted;
end;
else do;
timespan = intck('day',compare_date,admitted);
if timespan le 4 then do;
put 'deleting: ' _all_;
delete;
end;
else
compare_date = admitted;
end;
run;
deleted_user
Not applicable
Thank you for helping me 🙂

The coding works fine in my dataset though I get an error message in my log for every observation that I delete. Here is an example of an error message:

Deleting: compare_date=600 id=24306773 admission=271003 first.id=0 last.id=1 first.admission=1 last.admission=1 timespan=2 _error_=0 _N_=184978

Is that correct?

Second I do not understand whether this sas coding only compare the time span between the first admission and the following admissions. Or if it compares the time span between all admissions in the dataset.

:-) Susan
deleted_user
Not applicable
Susan,

It isn't really an error message, but just a write to the LOG. You can eliminate that by dropping the statement that begins with "PUT". It was used for diagnostic information only.

The comparison isn't just to the first admission, but neither is it comparing all possible combinations. It starts out comparing to the first admission, but then resets the comparison date whenever a new admission date is encountered (for a given patient) that was not subject to deletion.

Please look at what happens for my made-up patient number one, and note what records are dropped versus kept. I'm really not sure what outcome you'd actually want to have in that case. The 16Feb09 wasn't dropped because it was more than 4 days from the 11th, but if the 15th hadn't been deleted, then the 16th would have been within 4 days of the 15Feb and therefore possibly subject to elimination.

Did you want to do comparisons between all admissions within a patient?
deleted_user
Not applicable
Hi,

Thank you for your response!

I don't want to compare all admission dates for each patient. I have tried to illustrate what I want by an example:

Patient X has had the following admissions:

Ad 1: 11feb08
Ad 2: 13feb08
Ad 3: 16feb08
Ad 4: 18feb08
Ad 5: 25feb08

In this case, I would like to keep admission number 1 as the first admission and delete the admission on 13feb08. Then keep admission number 3 as the second admission and delete number 4 admission, since there is only 2 days between the second admission and this one. - So, what I would like to do is to change the "reference date" from admission date 1 to admission date 2.

How can I do this in SAS?

Thank you for your help!
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Using straightforward DATA step processing, you can assign SAS variables as needed, and you can use the technique IF/THEN DELETE; (or the converse, IF/THEN OUTPUT; ) to subset your dataset observations.

Scott Barry
SBBWorks, Inc.

Introduction to DATA Step Processing
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001302699.htm
deleted_user
Not applicable
Did you run the code I suggested against your example? As far as I can see, it deleted the two records you specified.

I'm not sure what you mean by changing the "reference" dates.
deleted_user
Not applicable
Thank you for your help

:-) Susan
deleted_user
Not applicable
Hi,

I am aware of the if then - delete statements.
However, some of the persons in our dateset has up to 117 admissions, so the editor will be quite long using the if then statements. This is why I have asked for help. So - I would be very glad if anyone can help me with this.

Thank you

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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