@dxiao2017 wrote:
Thanks a lot for your comments, I think it's a very good point that use macro (or any other advanced and complex procs and steps) only when it is necessary. However, I really do NOT think that question (as well as the solution) in the lesson was poorly designed, as 1) the learning material was to cover a lot of important contents of macro, and it was also designed for test preparation and had to include all the knowledge and techniques in the exam content guide, and therefore 2) while design the material, (I guess) the course developer was intended to integrate as much as possible contents in one question, and this makes the solution code complicated, and 3) besides the macro part of the built-in base 9.4 guide (SAS 9.4 macro language reference), as a new learner I think Macro1:Essential is the good official learning material I can find now.
For that question in my post, what made the solution code complex was the %let i=%eval(&i+1); statement, which now I guess was perhaps exactly what the material developer wanted learners to comprehend (which is not easy, e.g. how the two repeated %let i=; and %let yr=; statements work) , because that statement is used in a lot of scenarios when there is a do loop inside a macro.
A person who takes this macro course then goes out and has a real problem which is similar to the one presented, the person needs means by different years. And the person says "I learned how to do that in my class! I'll write a macro!" And I contend this is the wrong thing to do, and the person has learned the wrong lesson.
If I was going to design a macro class, I would not include using macros to replace other built-in tools in SAS. If the developer of the class wants to teach %let i=%eval(&i+1); there are plenty of ways to teach this without re-creating a BY statement with macro code.
... View more