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

how to remove the entire records of each id if it has values as either missing or zero.

 

i.e if i have id and have 5 values to it and next id 4 values and one of them is missing or zero than i want to ommit the entire id.

 

Any help

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

Assuming that you mean that you have data like this:

data have;
  input id value;
Cards;
1 3
1 4
1 3
2 0
2 3
3 .
3 5
3 6
4 1
;run;

And you want to get rid of all the ID=2 records, because there is one with VALUE=0, and all the ID=3 records because there is one with a missing VALUE.

Then this should do the trick, provided your data is sorted by ID:

data want;
  merge have(where=(not value) in=null) have;
  by id;
  if not null;
run;

  

View solution in original post

5 REPLIES 5
srinath3111
Quartz | Level 8

Hi ,

data ds;
infile datalines;
input id val;
datalines;
1 1
2 0
3 5
4 0
5 2
;
run;

 

 

data ds1;
set ds;
array dat[*] _all_;
do i=1 to dim(dat);
if dat(i)=0 then delete;
end;
output;
run;

 

Thanks

vraj1
Quartz | Level 8
data ds;
infile datalines;
input id val;
datalines;
1 1
1 0
2 0
2 1
2 2
2 0
3 5
4 0
5 2
;
run;

In this case id 2 should not come as it has one value  val as 0. I dont want any id if has either 0 or missing and want the rest of the id and val

srinath3111
Quartz | Level 8

Hi,

 

Then try,

data ds2;
merge ds(where=(not val) in=null) ds;
by id;
if not null;
run;

 

Thanks 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

It would help if you provided test data in the form of a datastep, and what the output should look like.  Just a guess:

data have (drop=flag);
  set have;
  array n{*} _numeric_;
  array c{*} _character_;
  do over n;
    if n in (.,0) then flag=1;
  end;
  do over c;
    if c="" then flag=1;
  end;
  if flag ne 1;
run;

Not tested as nothing provided.

s_lassen
Meteorite | Level 14

Assuming that you mean that you have data like this:

data have;
  input id value;
Cards;
1 3
1 4
1 3
2 0
2 3
3 .
3 5
3 6
4 1
;run;

And you want to get rid of all the ID=2 records, because there is one with VALUE=0, and all the ID=3 records because there is one with a missing VALUE.

Then this should do the trick, provided your data is sorted by ID:

data want;
  merge have(where=(not value) in=null) have;
  by id;
  if not null;
run;

  

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 1560 views
  • 0 likes
  • 4 in conversation