SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
blackandwhite
Obsidian | Level 7

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 
     
IDvar IDvar
11 11
10 10
10 10
10 10
11 11
10 10
11 11
10 10
20 30
20 30
20 30
20 31
30   
30   
30   
31   
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
input ID	var	; 	
cards;
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	 	 
;

proc sql;
create table want as
select *
from have
group by id
having n(id) ne sum(var=0);
quit;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

data have;
input ID	var	; 	
cards;
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	 	 
;

proc sql;
create table want as
select *
from have
group by id
having n(id) ne sum(var=0);
quit;
blackandwhite
Obsidian | Level 7

thanks!!

PeterClemmensen
Tourmaline | Level 20
data have;
input ID	var; 	
cards;
1	1
1	0
1	0
1	0
1	1
1	0
1	1
1	0
2	0
2	0
2	0
2	0
3	0
3	0
3	0
3	1
;

data want;
   if _N_ = 1 then do;
      declare hash h(dataset:'have(where=(var=1))');
      h.defineKey('ID');
      h.defineDone();
   end;

   set have;

   if h.check()=0;

run;

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2163 views
  • 2 likes
  • 3 in conversation