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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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