This procedure can be changed into set-based code. I just don't want to risk posting an incorrect solution and getting blamed for that as I don't have any sample data to test on or more details on what the code is meant to do.
For a minor change that might help a bit, you could wrap everything inside a single transaction. That will also help you to correct errors that you might get if the procedure fails without completing.