Re: Reduce datasteps in count and sum

Yes, your code could be simplified. For a specific suggestion it would be good to know how your final dataset should look like. Is the goal exactly the "output" you've posted? Or are, for example, Case_ID and Case_count only means to the end of creating Case_count_sum and you don't actually need them?

Re: Reduce datasteps in count and sum

I'm not so good at macros yet but how could I rewrite your code to a macro?

First, you should clarify if you really need a macro. I've seen all too many posts in this forum with (failed) attempts to use macro language where other techniques (mostly data and proc steps) would have been more appropriate. Maybe your case justifies writing a macro. If so, you have to decide which parts of the existing data step code are to be made flexible by using macro parameters.