%IF and macro conditional logic can only be used in a SAS Macro definition -- also sometimes called a SAS Macro program. A SAS Macro definition is like this:
%macro mymacpgm(parm1=, parm2=);
....some code including %IF, %DO, etc other code, datastep code, proc code, etc....
Now, to invoke the macro definition, you must do: