Search code examples
sassas-macro

Conditionally print a TITLE in SAS?


I am making a macro and want to display different titles for different variables that go through my macro.

I have been trying something like below:

%MYMACRO (VARIABLE);
%IF &VARIABLE='MYVARIABLE' %THEN TITLE1 'TITLE A';
    %ELSE TITLE1 'TITLE B';
/* MY MACRO STUFF */
%MEND MYMACRO;

This doesn't work. I am most likely not going about this in the proper manner either. I am wondering if there is an easy way to do this or if I need to do it manually each time I want to change my titles.


Solution

  • If your macro variable doesn't resolve to a quoted string, you will need to fix your conditional. For example like this:

    %IF "&VARIABLE"="MYVARIABLE" %THEN TITLE1 'TITLE A';
    

    This should be true when you run this:

    %mymacro(MYVARIABLE);
    

    Or the conditional in our example should resolve to true if you run this:

    %mymacro('MYVARIABLE');