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

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!

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.

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
  • 3 replies
  • 983 views
  • 2 likes
  • 3 in conversation