Syntax Colouring Inside SAS Macros

Andreas Kracht Frandsen

2019/08/14

This slight hack is a way to bypass how SAS syntax colouring behaves inside a macro, for the SAS Enhanced Editor.

Tip Regarding Syntax Colouring in Macros

I have always been annoyed by the fact that code inside a SAS macro isn’t syntax coloured.

%macro colourless;
    data noColour;
    set someData;
    run;
%mend;

Even though you can’t see it here, the above code block would have the same syntax colour for all its elements.1

There is a slight hack that can help you! All you have to do is create an empty dummy macro inside the original macro. Just like this.

%macro colourful;
    %macro disableTheDarkSide;
    %mend disableTheDarkSide;

    data colour;
    set someColourfulData;
    run;
%mend;

This essentially give you the syntax colouring defined in Tools -> Options -> Enhanced Editor back. This makes me happy and maybe also you. If you don’t know how to change the theme that controls the syntax colouring then check my blog posts out SAS 9.4 Enhanced Editor Custom Theme. But don’t fool yourself, SAS sees these nested macros as unexpected behaviour, and will maybe apply a fix2 sooner or later.

Feel free to comment with more SAS tips using Disqus.

Disclaimer: I am not affiliated with SAS Institute.


  1. highlight.js shows the correct colours.↩︎

  2. Well essentially it is not a fix.↩︎