BookmarkSubscribeRSS Feed
antona
Calcite | Level 5

Hi,

 

I would like to delete all rows for IDs who only have 0s for var

 

So, in the example below, I would  delete all rows for ID#2.

 

Somehow, I have to read all obs in each by group and then flag those who only have 0 but having trouble finding how..

 

Thanks very much!!

 

Have

 

 

Want

 

 

 

 

 

 

ID

var

 

ID

var

1

1

 

1

1

1

0

 

1

0

1

0

 

1

0

1

0

 

1

0

1

1

 

1

1

1

0

 

1

0

1

1

 

1

1

1

0

 

1

0

2

0

 

3

0

2

0

 

3

0

2

0

 

3

0

2

0

 

3

1

3

0

 

 

 

3

0

 

 

 

3

0

 

 

 

3

1

 

 

 

 

 

 

2 REPLIES 2
smijoss1
Quartz | Level 8

Sql 

 

select  from table 

where id not in ( select id from table group by ID having max(var) = 0 );

andreas_lds
Jade | Level 19

Hello @antona, welcome to the Community!

 

Is  var numeric or alphanumeric?

 

If it is alphanumeric try:

 

data killList;
   set have;
   by id;

   retain onlyZeros;

   if first.id then onlyZeros = 1;
   if var = '1' then onlyZeros = 0;
   if last.id and onlyZeros then output;

   keep id;
run;

data want;
   merge have killList(in= removeIt);
   by id;

   if removeIt then delete;
run;

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!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 2 replies
  • 515 views
  • 0 likes
  • 3 in conversation