Hi all,
Somewhat new to repeated measures but I'm working on a dataset that has repeated data. Below is a sample:
ID | Visit | Label |
AAA | 1 | XY |
AAA | 2 | Z |
AAA | 3 | . |
BBB | 1 | XY |
BBB | 2 | XY |
CCC | 1 | Z |
DDD | 1 | . |
DDD | 2 | . |
DDD | 3 | XY |
EEE | 1 | Z |
EEE | 2 | . |
FFF | 1 | XY |
GGG | 1 | Z |
HHH | 1 | . |
HHH | 2 | Z |
HHH | 3 | XY |
I want to delete any IDs where a label of XY appears at least once across any visit. The code I have tried below only seems to delete the exact rows that has an XY label, and not every row that belongs to that ID:
data want;
set have;
by id;
if label = "XY" then delete;
run;
Essentially, what I'd want to do is produce a table below that removes all other rows of that ID:
ID | Visit | Label |
CCC | 1 | Z |
EEE | 1 | Z |
EEE | 2 | . |
GGG | 1 | Z |
Any help would be much appreciated!
Thanks
data have;
input
ID $
Visit $
Label $;
cards;
AAA
1
XY
AAA
2
Z
AAA
3
.
BBB
1
XY
BBB
2
XY
CCC
1
Z
DDD
1
.
DDD
2
.
DDD
3
XY
EEE
1
Z
EEE
2
.
FFF
1
XY
GGG
1
Z
HHH
1
.
HHH
2
Z
HHH
3
XY
;
proc sql;
create table want as
select *
from have
where id not in (select id from have where label="XY");
quit;
data have;
input
ID $
Visit $
Label $;
cards;
AAA
1
XY
AAA
2
Z
AAA
3
.
BBB
1
XY
BBB
2
XY
CCC
1
Z
DDD
1
.
DDD
2
.
DDD
3
XY
EEE
1
Z
EEE
2
.
FFF
1
XY
GGG
1
Z
HHH
1
.
HHH
2
Z
HHH
3
XY
;
proc sql;
create table want as
select *
from have
where id not in (select id from have where label="XY");
quit;
A SQL DELETE statement will remove rows from the data set without rewriting the whole table.
proc sql undo_policy=none; delete from have where ID in (select ID from have where label='XY') ; quit;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.