|
Patrick,
How about creating a new variable (d_max) that is the max(of d1-d3), then
sorting the dataset by policy and descending d_max. That way if there is a
true indicator in the policy - it will be reflected in the first observation
for that policy. Then you can use the RETAIN and running indicator you were
talking about.
Maybe a little long-winded, but here is an example...
data test;
input P d1 d2 d3;
d_max = max(of d1-d3);
cards;
1 0 0 1
1 0 0 0
2 0 0 0
3 0 1 0
3 0 1 0
4 0 0 0
4 0 0 0
4 0 0 0
5 0 0 0
5 0 1 0
;
run;
proc sort data = test;
by p descending d_max;
run;
data test2;
retain delete_flag;
set test;
by p;
if first.p then do;
delete_flag = 'N';
if d_max gt 0 then do;
delete_flag = 'Y';
delete;
end;
end;
else if delete_flag = 'Y' then delete;
run;
Jack Clark
Research Analyst
Center for Health Program Development and Management
University of Maryland, Baltimore County
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Tramma,
Patrick
Sent: Thursday, January 04, 2007 10:36 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Deleting all records for a policy:
I have a dataset with multiple rows per policy and indicators of whether
or not I want to drop that policy. If any of the indicators are true,
then drop the policy. If p were the policy number and d1-d3 were the
drop codes, imagine a table like
P d1 d2 d3
1 0 0 1
1 0 0 0
2 0 0 0
3 0 1 0
3 0 1 0
4 0 0 0
4 0 0 0
4 0 0 0
5 0 0 0
5 0 1 0
I want to keep policies 2 and 4.
Ok, I know I can do this by creating a table of policy numbers to keep
and then re-joining them back to the original, but I'd rather not use
the space of another table. Using retain and a running indicator, you
can delete subsequent rows, but not prior ones. (In other words, the
problem I'm having is getting rid of the first row of policy 5 above.)
Any ideas?
Pat
====================
This email/fax message is for the sole use of the intended
recipient(s) and may contain confidential and privileged information.
Any unauthorized review, use, disclosure or distribution of this
email/fax is prohibited. If you are not the intended recipient, please
destroy all paper and electronic copies of the original message.
|