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));

 

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!

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.

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