Victor
Victor

Reputation: 17107

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?

Upvotes: 1

Views: 156

Answers (2)

Joe
Joe

Reputation: 63434

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).

Upvotes: 2

Tom
Tom

Reputation: 51621

There is no macro function trim. So it depends on whether you want to call the SAS supplied autocall macro %TRIM() or if you want to use the function TRIM(). If the later then you need to nest it inside the macro function %SYSFUNC() using %SYSFUNC(TRIM()).

Upvotes: 2

Related Questions