I am trying to keep records with results <=50. If one the ID has results >50 I want to remove the subject from further analysis. How can I do that?
ID |
Result |
1 |
50 |
1 |
23 |
2 |
16 |
2 |
7 |
2 |
26 |
3 |
55 |
3 |
30 |
3 |
43 |
3 |
5 |
4 |
50 |
4 |
23 |
I want an output like this
ID |
Result |
1 |
50 |
1 |
23 |
2 |
16 |
2 |
7 |
2 |
26 |
4 |
50 |
4 |
23 |
FWIW, this appears to be closer to what you are looking for. However, it can give you a note in the log about more than one data set have repeats of the BY variable:
data want;
merge have have (where=(result > 50) in=delete_me);
by id;
if delete_me then delete;
run;
proc sql;
create table want as
select t1.* from have t1
where ID not In (select distinct t2.ID from have t2 where t2.results > 50);
quit;
@hjjijkkl wrote:
I am trying to keep records with results <=50. If one the ID has results >50 I want to remove the subject from further analysis. How can I do that?
ID
Result
1
50
1
23
2
16
2
7
2
26
3
55
3
30
3
43
3
5
4
50
4
23
I want an output like this
ID
Result
1
50
1
23
2
16
2
7
2
26
4
50
4
23
Some other methodologies include:
All of these essentially have two passes of the data in one form or another but SQL and the DoW loop let it "appear" to be one step.
@hjjijkkl wrote:
is there another way to do it besides proc sql?
FWIW, this appears to be closer to what you are looking for. However, it can give you a note in the log about more than one data set have repeats of the BY variable:
data want;
merge have have (where=(result > 50) in=delete_me);
by id;
if delete_me then delete;
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 25. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.