Hello All,
Can you let me know the difference between when we use a Base SAS function with %SYSFUNC vs when we use a macro function directly?
For instance, what is the difference between %SYSFUNC(SUBSTR(&VAR1,1,5)) and %SUBSTR(&VAR1,1,5). Both seem to produce the same result. If there is no difference, then why do we have a separate %SUBSTR especially for Macro processing?
Thanks in anticipation!
%SUBSTR has existed for decades, along with a handful of additional macro language functions.
At some point, SAS decided that macro language should be able to use hundreds of functions that were available to DATA steps, but didn't exist in macro language. Instead of rewriting those functions for macro language, SAS invented %SYSFUNC which lets you call most DATA step functions (SUBSTR included). To prevent existing programs from breaking, no functionality was removed. Both versions are acceptable. But why would you add %SYSFUNC when you don't have to? It only complicates the expression.
The macro preprocessor is a text processor, so it makes sense to have macro equivalents of commonly used string manipulation functions to avoid unnecessary %sysfunc's.
%SUBSTR has existed for decades, along with a handful of additional macro language functions.
At some point, SAS decided that macro language should be able to use hundreds of functions that were available to DATA steps, but didn't exist in macro language. Instead of rewriting those functions for macro language, SAS invented %SYSFUNC which lets you call most DATA step functions (SUBSTR included). To prevent existing programs from breaking, no functionality was removed. Both versions are acceptable. But why would you add %SYSFUNC when you don't have to? It only complicates the expression.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.