I suggest you do some debugging by using %PUT statements inside the macro program, so you can track how the various values are getting set/changed.
Also, I would recommend testing this macro program as a standalone program. My rule for writing a stored process (SP) is to have a working SAS program -- one that executes correctly in a standalone SAS session (such as running from Display Manager or an EG code node) BEFORE turning that program and/or its macro programs into a stored process.
You might also consider working with Tech Support on this issue, as it is hard to debug a stored process without seeing how the SP is defined, what server it's running on, what parameters are being passed, etc, etc. In fact, this code snippet doesn't look like -ALL- of your stored process -- it looks like a macro that's being used -inside- a bigger stored process program. Where are your %stpbegin/%stpend -- what output is being generated by the SP - -what is the purpose of this macro program??? Tech Support could look at your WHOLE stored process and all of your code and they may be able to help you come to a quicker resolution.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.