BookmarkSubscribeRSS Feed

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;

1 REPLY 1
Reeza
Super 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));

 

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 1045 views
  • 1 like
  • 2 in conversation