Help using Base SAS procedures

selecting the largest variable

Reply
Regular Contributor
Posts: 161

selecting the largest variable

Hello SAS experts,

I have a series of variables and would like to choose the variable with the largest value.

Some background:

I have ran a program that classifies the probability of  individuals belonging to a specific class(y1-y8). I need to write a code to select the highest probability among these classes. I have attached a sample file with 10,000 examinees and their probability for belonging to each class. How can I select the variable with highest value/probability?

Thank you for any help in advance

Attachment
Trusted Advisor
Posts: 1,300

selecting the largest variable

Not quite sure from your question what type of maximum value you are looking for?

Here are two possible answers to two possible questions...

find the by row maximum value: the max function. ie. ymax=max(of y1-y8);

find the by column maximum value: one option is proc summary. ie. proc means data=out_2 max; var y1-y8; run;

PROC Star
Posts: 7,363

selecting the largest variable

I read your request slightly differently.  Would the following provide what you want?

proc summary data=out_2;

  var y1-y8;

  output out=need (drop=_Smiley Happy mean=;

run;

proc transpose data=need out=want;

run;

proc sql;

  select *

    from want

      having col1 eq max(col1)

  ;

quit;

Super User
Posts: 9,681

selecting the largest variable

libname xx v9 'c:\';
data want;
 set xx.out_2;
 array _y{*} y1-y8;
 max=max(of y1-y8);
 i=whichN(max,of _y{*});
 max_var=vname(_y{i});
 drop max i;
run;

Ksharp

Ask a Question
Discussion stats
  • 3 replies
  • 785 views
  • 0 likes
  • 4 in conversation