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?
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.
If 2 or more variables have the same maximum value, do you need to know all their names?
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.
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.
input var bar nar kar lar ; * just some variable names ;
1 8 2 77 13
5 3 1 4 6