Search code examples
if-statementsasmacrossas-macro

SAS Conditionally Call a Macro


I have a macro called "checks" and I would like to only call it when a previously defined macro variable (called run_type)= model. Here's what I've tried so far:

%if &run_type. = 'Model' %then %do;
%checks;
%end;

But this doesn't work, can anyone help?


Solution

  • It will work fine as long as the value of RUN_TYPE is literally 'Model' complete with the mixed case and enclosing single quotes.

    If instead the value of RUN_TYPE is just Model or perhaps even model or MODEL then you might want to use this comparison instead.

    %if %qupcase(&run_type.) = MODEL %then %do;
    %checks;
    %end;