Help using Base SAS procedures

deleting observations

Reply
N/A
Posts: 0

deleting observations

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
N/A
Posts: 0

Re: deleting observations

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;
N/A
Posts: 0

Re: deleting observations

Thank you for helping me Smiley Happy

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
N/A
Posts: 0

Re: deleting observations

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?
N/A
Posts: 0

Re: deleting observations

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!
Super Contributor
Super Contributor
Posts: 3,174

Re: deleting observations

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
N/A
Posts: 0

Re: deleting observations

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.
N/A
Posts: 0

Re: deleting observations

Thank you for your help

:-) Susan
N/A
Posts: 0

Re: deleting observations

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
Ask a Question
Discussion stats
  • 8 replies
  • 171 views
  • 0 likes
  • 2 in conversation