BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ritam2011
Calcite | Level 5

Guys, I am unsure how to proceed at this point.  So I have thousands of rows of data with a hundred different fields.  The field values are all integer values.  I would like to identify which field contains the highest value in each row. 

I can use the LARGEST() function to identify the 3 highest values in each row, but what I really need is the names of those 3 fields (added as 3 extra fields).  Any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

What happens if you have multiples? Which variable would you take? or would you take 3 of the same?

Use an array of sorts with the whichn and vname function. 

data have;

set sashelp.pricedata;

array pr{*} price1--price17;

firstvar=vname(pr[whichn(largest(1, of pr{*}), of pr{*})]);

run;

View solution in original post

3 REPLIES 3
Reeza
Super User

What happens if you have multiples? Which variable would you take? or would you take 3 of the same?

Use an array of sorts with the whichn and vname function. 

data have;

set sashelp.pricedata;

array pr{*} price1--price17;

firstvar=vname(pr[whichn(largest(1, of pr{*}), of pr{*})]);

run;

ritam2011
Calcite | Level 5

Thanks Reeza -- VNAME was what I was looking for.  So I have the above working, the issue now is that some of the rows have all zero values in the fields, and the output in these cases is the first fieldname repeated all 3 times.  I would like simply not to display any fieldname if values are 0.  But how to do this with the above code?

Ksharp
Super User

Then using array will give you more control.

Since not seeing your data ,it is hard to code exactly.

Ksharp

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1831 views
  • 2 likes
  • 3 in conversation