If you used the multiprocessing library you could really make this Python code fly. That would exceed the SAS performance by many orders of magnitude.