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

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

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
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;
asgee
Obsidian | Level 7
Hi @novinosrin ! Thanks so much for helping me out. The code works perfectly! I definitely need to look into learning more about proc sql.
RichardDeVen
Barite | Level 11

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3201 views
  • 2 likes
  • 3 in conversation