I'd imagine that you could just go through the max check thing but ignoring the highest option once (by having an extra variable to figure out if you ignored the change once so far or not, in case you have two variables sharing the maximum). (If you want to ignore the value if it is equal to max then it should be easier to do).
Note that %EXTRA starts as 0, it is the extra variable I'm using for finding the second highest. %MAX2 is second highest.
IF %MAX = %STRENGTH THEN %EXTRA := 1
ELSE %MAX2 := %STRENGTH
IF %MAX = %SPEED THEN IF %EXTRA = 1 THEN %MAX2 := %SPEED ELSE
IF %EXTRA != 1 THEN
IF %MAX2 < %SPEED THEN %MAX2 := %SPEED
IF %MAX = %ACCURACY THEN IF %EXTRA = 1 THEN %MAX2 := %ACCURACY ELSE
IF %EXTRA != 1 THEN
IF %MAX2 < %ACCURACY THEN %MAX2 := %ACCURACY
IF %MAX = %INTELLIGENCE THEN IF %EXTRA = 1 THEN %MAX2 := %INTELLIGENCE ELSE
IF %EXTRA != 1 THEN
IF %MAX2 < %INTELLIGENCE THEN %MAX2 := %INTELLIGENCE
IF %MAX = %STEALTH THEN IF %EXTRA = 1 THEN %MAX2 := %STEALTH ELSE
IF %EXTRA != 1 THEN
IF %MAX2 < %STEALTH THEN %MAX2 := %STEALTH
IF %STRENGTH = %MAX2 THEN # Strength is second highest
ELSE IF %SPEED = %MAX2 THEN # Speed is second highest
ELSE IF %ACCURACY = %MAX2 THEN # Accuracy is second highest
ELSE IF %INTELLIGENCE = %MAX2 THEN # Intelligence is second highest
ELSE # Stealth is second highest
Hope this works, according to my primitive testing it should(?) but I don't trust myself. I'm also not sure if I structured it properly, but it can be rearranged as desired.
EDIT - There is some redundancy in my checks, I think, but I'm too lazy to go check it myself so I'll just leave this unedited. Someone can always post a better version anyway.