BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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!
  • 5 REPLIES 5
    Peter_C
    Rhodochrosite | Level 12
    what is your preference?
    PROC TRANSPOSE, PROC RANK, PROC TRANSPOSE.
    or ARRAY handling in a data step?
    PeterC
    deleted_user
    Not applicable
    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.
    data_null__
    Jade | Level 19
    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]
  • SASPhile
    Quartz | Level 8
    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.
    deleted_user
    Not applicable
    Thank you _null_, that is exactly what I was looking for. I'll have to jot that one down for future reference.

    Cheers!

    sas-innovate-2024.png

    Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

    Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

     

    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.

    Click image to register for webinarClick image to register for webinar

    Classroom Training Available!

    Select SAS Training centers are offering in-person courses. View upcoming courses for:

    View all other training opportunities.

    Discussion stats
    • 5 replies
    • 1074 views
    • 0 likes
    • 4 in conversation