DATA Step, Macro, Functions and more

Where clause on my Array

Reply
anonymous_user
Posts: 0

Where clause on my Array

Hi, 

 

I have managed to identify the MAX values by using the code below, but how do include the month with has the MAX value? I can manually work out it's September but would like to code it up to provide that answer.


data steve;
input arrbal_jan15 arrbal_feb15 arrbal_mar15 arrbal_apr15 arrbal_may15 arrbal_jun15
arrbal_jul15 arrbal_aug15 arrbal_sep15 arrbal_oct15 arrbal_nov15 arrbal_dec15;
datalines;
10 50 1 66 54 10 12 154 188 12 111 13

90 1 87 88 76 10 265 121 120 41 105 29
;
run;

 

data test (drop=i);
set steve;
array arrearsbal (12) arrbal_jan15 arrbal_feb15 arrbal_mar15 arrbal_apr15 arrbal_may15 arrbal_jun15
arrbal_jul15 arrbal_aug15 arrbal_sep15 arrbal_oct15 arrbal_nov15 arrbal_dec15;
do i=1 to 12;
max_arrears_balance=max(max_arrears_balance,arrearsbal(i));
end;
run;

Super User
Posts: 19,820

Re: Where clause on my Array

Posted in reply to anonymous_user

use a function on the array so you don't need a loop. 

 

Maxval = max(of arrearsbal(*));

 

Lookup the vname function, but what happens if you have ties for the max? 

 

Max_index = whichn(maxval, of arrearsbal(*));

name = vname(arrearsbal(max_index));

 

Ask a Question
Discussion stats
  • 1 reply
  • 184 views
  • 1 like
  • 2 in conversation