Hi,
I could not find a solution for this problem on the board so I thought I would ask instead.
As the long subject line says,
If a variable A meets certain conditions then I want to delete all observations with the same variable B as the other observation.
If A >10 and B is 5, then I want to remove all variables where B=5.
I want this
Obs A B
1 5 10
2 11 10
3 1 11
4 9 11
5 12 12
6 3 13
To become this
1 1 11
2 9 11
3 3 13
Thanks in advance!
Here you go:
data have;
input a b;
datalines;
5 10
11 10
1 11
9 11
12 12
3 13
;
data want;
if _n_=1 then
do;
dcl hash h1(dataset:'have(where=(a>10))');
h1.defineKey('b');
h1.defineDone();
end;
set have;
if h1.check()=0 then delete;
run;
proc print data=want;
run;
I don't see one obs where B=5?
Here you go:
data have;
input a b;
datalines;
5 10
11 10
1 11
9 11
12 12
3 13
;
data want;
if _n_=1 then
do;
dcl hash h1(dataset:'have(where=(a>10))');
h1.defineKey('b');
h1.defineDone();
end;
set have;
if h1.check()=0 then delete;
run;
proc print data=want;
run;
Ok. I would go with the solution by @Patrick then.
Alternatively you could do
data have;
input a b;
datalines;
5 10
11 10
1 11
9 11
12 12
3 13
;
data want;
array _ {1000000} _temporary_;
do until (lr1);
set have(where=(a>10)) end=lr1;
_[b]=1;
end;
do until (lr2);
set have end=lr2;
if _[b] ne 1 then output;
end;
stop;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: