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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.