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
- /
- ODS and Base Reporting
- /
- maximum value

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
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-26-2006 09:23 AM

Hi,

Here's my problem: I have 10 variables (columns) and I would like to create an other variable which would consist of the highest value from the preceding 10 variables. The thing is, I don't actually want the value, but the variable's name corresponding to that maximum value. Could you help me?

Many thanks!

Here's my problem: I have 10 variables (columns) and I would like to create an other variable which would consist of the highest value from the preceding 10 variables. The thing is, I don't actually want the value, but the variable's name corresponding to that maximum value. Could you help me?

Many thanks!

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

07-26-2006 09:36 AM

A suggestion:

1. Find the maximum value of all 10 variables using MAX() function.

2. Create an array of all 10 variables.

3. Compare the maximum value to each variable in the array in a DO..END loop, and note which variable has the same value as the maximum.

A question:

If 2 or more variables have the same maximum value, do you need to know all their names?

.......Phil

1. Find the maximum value of all 10 variables using MAX() function.

2. Create an array of all 10 variables.

3. Compare the maximum value to each variable in the array in a DO..END loop, and note which variable has the same value as the maximum.

A question:

If 2 or more variables have the same maximum value, do you need to know all their names?

.......Phil

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

07-26-2006 10:30 AM

thanks!

To your question: no, I am deleting those data (if 2 have the same and the largest value)

another question: is there a command to find the 2nd largest value?

To your question: no, I am deleting those data (if 2 have the same and the largest value)

another question: is there a command to find the 2nd largest value?

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

07-26-2006 10:46 AM

I'm not aware of a "2nd largest value" function.

As a workaround you could repeat my previous code, but, knowing which variable held the maximum value, exclude that one from the array and find the maximum of the remaining 9. Alternatively assign a very small, or large negative, value to the "maximum" variable, then repeat the code asis.

.......Phil

As a workaround you could repeat my previous code, but, knowing which variable held the maximum value, exclude that one from the array and find the maximum of the remaining 9. Alternatively assign a very small, or large negative, value to the "maximum" variable, then repeat the code asis.

.......Phil

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

07-27-2006 05:18 AM

Hi,

there is a LARGEST(k, variable_list) beginning with SAS9 ; k equals 1 if you want the maximum, k=2 will give you the second greatest value, and so on.

For your problem of recording the variables names according to their order, is the following example of any help ?

DATA work.test ;

INPUT x1-x5 ;

CARDS ;

45 454 484 21 2

2121 5156 5645 451 5451

5151 2121 21 313 26

55 64 65 1 231

;

RUN ;

DATA work.whos_who (DROP = nth: j) ;

SET work.test ;

ARRAY myXs _NUMERIC_ ;

ARRAY theirNames $ name1-name5 ;

DO nth = 1 TO DIM(myXs) ;

nth_biggest = LARGEST(nth, OF x1-x5) ;

DO j = 1 TO DIM(myXs) ;

IF nth_biggest = myXs(j) THEN theirNames(nth) = VNAME(myXs(j)) ;

END ;

END ;

RUN ;

there is a LARGEST(k, variable_list) beginning with SAS9 ; k equals 1 if you want the maximum, k=2 will give you the second greatest value, and so on.

For your problem of recording the variables names according to their order, is the following example of any help ?

DATA work.test ;

INPUT x1-x5 ;

CARDS ;

45 454 484 21 2

2121 5156 5645 451 5451

5151 2121 21 313 26

55 64 65 1 231

;

RUN ;

DATA work.whos_who (DROP = nth: j) ;

SET work.test ;

ARRAY myXs _NUMERIC_ ;

ARRAY theirNames $ name1-name5 ;

DO nth = 1 TO DIM(myXs) ;

nth_biggest = LARGEST(nth, OF x1-x5) ;

DO j = 1 TO DIM(myXs) ;

IF nth_biggest = myXs(j) THEN theirNames(nth) = VNAME(myXs(j)) ;

END ;

END ;

RUN ;

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

07-27-2006 09:16 AM

Olivier!

Merci! thank you so much!

Merci! thank you so much!

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

07-27-2006 10:49 AM

Hi,

Why not putting your variables in an array, sort the array and automatically you will have an easy access to the highest value, second highest, lowest, etc ...

There is an experimental array sorting function in SAS 9, try the example below.

Good luck,

Otto.

data t;

infile cards;

input var bar nar kar lar ; * just some variable names ;

cards;

1 8 2 77 13

5 3 1 4 6

;

run;

data tt;

set t;

array v var bar nar kar lar ;

call sortn (of v );

run;

Why not putting your variables in an array, sort the array and automatically you will have an easy access to the highest value, second highest, lowest, etc ...

There is an experimental array sorting function in SAS 9, try the example below.

Good luck,

Otto.

data t;

infile cards;

input var bar nar kar lar ; * just some variable names ;

cards;

1 8 2 77 13

5 3 1 4 6

;

run;

data tt;

set t;

array v

call sortn (of v

run;