DATA Step, Macro, Functions and more

Removing the lowest value in grouped variables

Reply
N/A
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,177

    Re: Removing the lowest value in grouped variables

    Posted in reply to deleted_user
    what is your preference?
    PROC TRANSPOSE, PROC RANK, PROC TRANSPOSE.
    or ARRAY handling in a data step?
    PeterC
    N/A
    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.
    Respected Advisor
    Posts: 3,799

    Re: Removing the lowest value in grouped variables

    Posted in reply to deleted_user
    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: 673

    Re: Removing the lowest value in grouped variables

    Posted in reply to data_null__
    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.
    N/A
    Posts: 0

    Re: Removing the lowest value in grouped variables

    Posted in reply to data_null__
    Thank you _null_, that is exactly what I was looking for. I'll have to jot that one down for future reference.

    Cheers!
    Ask a Question
    Discussion stats
    • 5 replies
    • 157 views
    • 0 likes
    • 4 in conversation