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 2024

Innovate_SAS_Blue.png

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. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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