Thanks for these examples. For generating code I tend to use PROC SQL to create a pseudo-array of macro variables from the data and then use those in a macro loop. For pure data manipulation I use pure SQL; for example your SALE_CATEGORY example can be done as a join with a table of recodings. You could have used PROC FORMAT there too. I find non-procedural code easier to write and maintain.

Could your first example be done with a BY statement?

Please could you explain the advantages and disadvantages of the these various approaches?