Search code examples
sassas-macro

Correct syntax for invoking a macro function within a macro


Let us say I write a SAS macro and in that macro, I wish to invoke the macro function TRIM. Do I need to write:

%sysfunc(%trim(&text.))

Or %trim(&text.)

Or %sysfunc(trim(&text.))

What is the correct syntax?


Solution

  • The basic rule regarding SYSFUNC or not SYSFUNC:

    If you are running a function from this page, the Dictionary of SAS Functions and Call Routines, then you use SYSFUNC.

    If it's on this page or the related pages ("Autocall Macros" is relevant here), then you use % and don't use SYSFUNC.

    In some cases, and %trim is one of them, you can do both - getting more or less the same result (there may be small differences in how the SYSFUNC and the autocall macro work, particularly related to macro quoting).