Have you checked whether %sys itself is set correctly? I'm willing to bet that it's not. You're only checking %sys.bk<%sys>, and that only if it's different from $5. Apart from the fact that you shouldn't check things after they are used but rather before, you should check them in the order they change, eg if %b relies on %a, you don't check %b directly: first you check %a. Once you are sure %a is ok, then check %b.