turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Removing the lowest value in grouped variables

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-02-2009 06:34 PM

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!

If I have an array -

array z

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!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

12-03-2009 02:55 AM

what is your preference?

PROC TRANSPOSE, PROC RANK, PROC TRANSPOSE.

or ARRAY handling in a data step?

PeterC

PROC TRANSPOSE, PROC RANK, PROC TRANSPOSE.

or ARRAY handling in a data step?

PeterC

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Peter_C

12-03-2009 04:06 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

12-03-2009 07:07 AM

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]

[pre]

data have;

input x1-x5 y1 y2 y3 y10;

array x[5];

array y

when='Before';

output;

do i = 2,1;

x[whichN(smallest(i,of x

y[whichN(smallest(i,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]

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to data_null__

12-03-2009 11:45 AM

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.

I have gone through the documentation and the example is not clearly explained.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to data_null__

12-03-2009 04:59 PM

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

Cheers!

Cheers!