I'm looking how I can keep only those with var1=1 and var2=1. If one participants has var1=1 and var2=1, I was to keep all rows of the participants.
This is the initial dataset
data new;
infile cards missover;
input id var1 var2;
cards;
11 1 0
11 1 0
12 1 1
12 1 1
12 0 1
13 1 1
14 0 1
15 1 1
16 1 1
17 0 1
17 0 1
17 1 1
17 0 0
run;
The final dataset should be like this:
data new1;
infile cards missover;
input id var1 var2;
cards;
12 1 1
12 1 1
12 0 1
13 1 1
15 1 1
16 1 1
17 0 1
17 0 1
17 1 1
17 0 0
run;
Thank you!
This is a good example of applying a self-merge of a subset of a dataset with the entire dataset, as in:
data new;
infile cards missover;
input id var1 var2;
cards;
11 1 0
11 1 0
12 1 1
12 1 1
12 0 1
13 1 1
14 0 1
15 1 1
16 1 1
17 0 1
17 0 1
17 1 1
17 0 0
run;
data new1;
merge new (where=(var1=1 and var2=1) in=inkeep)
new;
by id;
if inkeep;
run;
Why does this work:
This is a good example of applying a self-merge of a subset of a dataset with the entire dataset, as in:
data new;
infile cards missover;
input id var1 var2;
cards;
11 1 0
11 1 0
12 1 1
12 1 1
12 0 1
13 1 1
14 0 1
15 1 1
16 1 1
17 0 1
17 0 1
17 1 1
17 0 0
run;
data new1;
merge new (where=(var1=1 and var2=1) in=inkeep)
new;
by id;
if inkeep;
run;
Why does this work:
Thank you very much for the solution!!!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.