Not applicable
Posts: 0

# Removing the lowest value in grouped variables

Hi.

If I have an array -

array z
• x1-x5 y1-y10;

and I want to get rid of the lowest 2 values in x1-x5, and the lowest 2 values of y1-y10, how do I get rid of the values, and not the entire observation/variable? Or conversely, is there a way to just keep a subset of the kth highest values in x1-x5, y1-y10?

Sorry for the bad tables, but -
I have this:
obs x1 x2 x3 x4 x5 y1 y2 y3 ... y10
1 10 9 2 5 3 9 9 0 ... 2
2 0 0 7 10 9 3 10 9 ... 10
...
500 9 5 9 5 9 10 5 6 ... 7

what i want is something like:

obs x1 x2 x3 x4 x5 y1 y2 y3 ... y10
1 10 9 . 5 . 9 9 . ... .
2 . . 7 10 9 . 10 9 ... 10
...
500 9 . 9 . 9 10 . . ... 7

thanks!
• Valued Guide
Posts: 2,191

## Re: Removing the lowest value in grouped variables

PROC TRANSPOSE, PROC RANK, PROC TRANSPOSE.
or ARRAY handling in a data step?
PeterC
Not applicable
Posts: 0

## Re: Removing the lowest value in grouped variables

Knowing how to do it in an array within the data step would be my preference. I thought about trying the transpose rank transpose but it seems like an inefficient way to go about it.
Posts: 3,852

## Re: Removing the lowest value in grouped variables

Which Smallest.

[pre]
data have;
input x1-x5 y1 y2 y3 y10;
array x[5];
array y
• y:;
when='Before';
output;
do i = 2,1;
x[whichN(smallest(i,of x
• ),of x
• )] = .;
y[whichN(smallest(i,of y
• ),of y
• )] = .;
end;
when='After';
output;
cards;
10 9 2 5 3 9 9 0 2
0 0 7 10 9 3 10 9 10
9 5 9 5 9 10 5 6 7
;;;;
run;
proc print;
run;
[/pre]
• Super Contributor
Posts: 713

## Re: Removing the lowest value in grouped variables

Does this hold good only for two smallest values?if the need be for 3 or 4 lowest values how will this work?
I have gone through the documentation and the example is not clearly explained.
Not applicable
Posts: 0