So @Tom has provided a very good solution. Let me try to explain why your original code doesn't work.
The %IF statement cannot access data set variable values. So you want to test to see if, for example, VAR2, has a value that is equal to 'Related'. %IF cannot do this, it has no idea what the values of VAR2 at any point in time. Data step tools, such as ARRAYs, the WHICHC function, and the good old IF statement, can do this.
So had the code been written with data step tools it might have worked. Please keep this in mind in the future when you try to write macros.
... View more