Does the code included do everything you want to do?
I see no indication of a SOLD variable being used anywhere.
In general before you convert your code to a macro you should be ensuring you have code that works and does what you need.
Once you have working code for one of your cases here's a tutorial on converting a working program to a macro This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it 🙂 https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md And here are some other examples of common macro usage https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716
... View more