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

Following is the example of data I have. I want to delete the rows where ClaimStatus = reversed and also delete the associated 'filled' claim. E.g. For ID = 1, I want to delete rows 2 and 3. For ID= 2, I want to delete rows 1 and 2. For ID=3, I want to delete 1 and 2. Please advise on how do I delete these rows from my data. Thanks.

 

IDTransactionDatePayerClaimAmountPaidCopayContractCostRxIdRefillNumberNDCfillDateQuantityDaysSupplyClaimStatus
1abc125011.6912340xzy25Feb201611Filled
1abc102511.6912340xyz25Feb201611Filled
1abc-10-25-11.6912340xyz25Feb2016-1-1Reversed
2efg-1-769.5-50-775.3656782lmn11Nov2017-30-30Reversed
2efg1769.550775.3656782lmn11Nov20173030Filled
2efg1360.3550387.6856782lmn15/11/20171530Filled
3cde-10-14.59-0.64889105xyz15/11/2017-30 Reversed
3cde1014.590.64889105xyz15/11/201730 Filled
3cde1040.64889105xyz15/11/201730 Filled
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

@monali  This is much safer 

 

data have;
infile cards truncover;
input (ID	TransactionDate	Payer	ClaimAmountPaid	Copay	ContractCost	RxId	RefillNumber	NDC	fillDate	Quantity	DaysSupply	ClaimStatus) (:$30.);
cards;
1	abc	1	25	0	11.69	1234	0	xzy	25-Feb-16	1	1	Filled
1	abc	1	0	25	11.69	1234	0	xyz	25-Feb-16	1	1	Filled
1	abc	-1	0	-25	-11.69	1234	0	xyz	25-Feb-16	-1	-1	Reversed
2	efg	-1	-769.5	-50	-775.36	5678	2	lmn	11-Nov-17	-30	-30	Reversed
2	efg	1	769.5	50	775.36	5678	2	lmn	11-Nov-17	30	30	Filled
2	efg	1	360.35	50	387.68	5678	2	lmn	15/11/2017	15	30	Filled
3	cde	-1	0	-14.59	-0.648	8910	5	xyz	15/11/2017	-30	.	Reversed
3	cde	1	0	14.59	0.648	8910	5	xyz	15/11/2017	30	.	Filled
3	cde	1	0	4	0.648	8910	5	xyz	15/11/2017	30	.	Filled
;
data want;
_n=0;
do _n_=1 by 1 until(last.id);
set have;
by id;
array t(999);
k=sum(Quantity,lag(Quantity));
if k=0 then do; _n+1;t(_n)=_n_-1;_n+1;t(_n)=_n_;end;
end;
do _n_=1 by 1 until(last.id);
set have;
by id;
if _n_ not in t then output;
end;
drop _: t:;
run;

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

Is RxOutcome a variable? in that case, I don't see it in your example data?

monali
Obsidian | Level 7

sorry, the variable is ClaimStatus. I edited the original post. 

PeterClemmensen
Tourmaline | Level 20

Ok. First part of the problem is solved below. However, what exactly constitutes an 'associated filled claim'? I do see the claims you refer to in the data, but what is the exact logic to put in a program?

 

data have;
input ID TransactionDate $ Payer ClaimAmountPaid Copay ContractCost RxId RefillNumber NDC $ fillDate:anydtdte12. Quantity DaysSupply $ ClaimStatus $;
infile datalines missover;
format fillDate date9.;
datalines;
1 abc 1 25 0 11.69 1234 0 xzy 25Feb2016 1 1 Filled
1 abc 1 0 25 11.69 1234 0 xyz 25Feb2016 1 1 Filled
1 abc -1 0 -25 -11.69 1234 0 xyz 25Feb2016 -1 -1 Reversed
2 efg -1 -769.5 -50 -775.36 5678 2 lmn 11Nov2017 -30 -30 Reversed
2 efg 1 769.5 50 775.36 5678 2 lmn 11Nov2017 30 30 Filled
2 efg 1 360.35 50 387.68 5678 2 lmn 15/11/2017 15 30 Filled
3 cde -1 0 -14.59 -0.648 8910 5 xyz 15/11/2017 -30 Reversed
3 cde 1 0 14.59 0.648 8910 5 xyz 15/11/2017 30 Filled
3 cde 1 0 4 0.648 8910 5 xyz 15/11/2017 30 Filled
;

data want;
   set have;
   where ClaimStatus ne 'Reversed';
run;

 

monali
Obsidian | Level 7

The associated 'filled' claim has positive contract cost. See rows 2 and 3 for ID=1. The contractCost is 11.69 for row where ClaimStatus = filled and contractCost is (-11.69) where claimStatus = reversed. And, for both these rows (that I want to exclude) the columns RxId, RefillNumber, NDC, and fillDate need to have the same value. 

novinosrin
Tourmaline | Level 20

data have;
infile cards truncover;
input (ID	TransactionDate	Payer	ClaimAmountPaid	Copay	ContractCost	RxId	RefillNumber	NDC	fillDate	Quantity	DaysSupply	ClaimStatus) (:$30.);
cards;
1	abc	1	25	0	11.69	1234	0	xzy	25-Feb-16	1	1	Filled
1	abc	1	0	25	11.69	1234	0	xyz	25-Feb-16	1	1	Filled
1	abc	-1	0	-25	-11.69	1234	0	xyz	25-Feb-16	-1	-1	Reversed
2	efg	-1	-769.5	-50	-775.36	5678	2	lmn	11-Nov-17	-30	-30	Reversed
2	efg	1	769.5	50	775.36	5678	2	lmn	11-Nov-17	30	30	Filled
2	efg	1	360.35	50	387.68	5678	2	lmn	15/11/2017	15	30	Filled
3	cde	-1	0	-14.59	-0.648	8910	5	xyz	15/11/2017	-30	.	Reversed
3	cde	1	0	14.59	0.648	8910	5	xyz	15/11/2017	30	.	Filled
3	cde	1	0	4	0.648	8910	5	xyz	15/11/2017	30	.	Filled
;

data want;
merge have have(firstobs=2 keep= claimstatus id rename= (id =_id claimstatus=_claimstatus));
_k=lag(quantity);
if (id=_id and claimstatus ne _claimstatus) or sum(_k,quantity)=0 then _f=1;
if not _f;
drop _:;
run;
novinosrin
Tourmaline | Level 20

@monali  This is much safer 

 

data have;
infile cards truncover;
input (ID	TransactionDate	Payer	ClaimAmountPaid	Copay	ContractCost	RxId	RefillNumber	NDC	fillDate	Quantity	DaysSupply	ClaimStatus) (:$30.);
cards;
1	abc	1	25	0	11.69	1234	0	xzy	25-Feb-16	1	1	Filled
1	abc	1	0	25	11.69	1234	0	xyz	25-Feb-16	1	1	Filled
1	abc	-1	0	-25	-11.69	1234	0	xyz	25-Feb-16	-1	-1	Reversed
2	efg	-1	-769.5	-50	-775.36	5678	2	lmn	11-Nov-17	-30	-30	Reversed
2	efg	1	769.5	50	775.36	5678	2	lmn	11-Nov-17	30	30	Filled
2	efg	1	360.35	50	387.68	5678	2	lmn	15/11/2017	15	30	Filled
3	cde	-1	0	-14.59	-0.648	8910	5	xyz	15/11/2017	-30	.	Reversed
3	cde	1	0	14.59	0.648	8910	5	xyz	15/11/2017	30	.	Filled
3	cde	1	0	4	0.648	8910	5	xyz	15/11/2017	30	.	Filled
;
data want;
_n=0;
do _n_=1 by 1 until(last.id);
set have;
by id;
array t(999);
k=sum(Quantity,lag(Quantity));
if k=0 then do; _n+1;t(_n)=_n_-1;_n+1;t(_n)=_n_;end;
end;
do _n_=1 by 1 until(last.id);
set have;
by id;
if _n_ not in t then output;
end;
drop _: t:;
run;
monali
Obsidian | Level 7

Thanks. This works!