%SYSFUNC(SUBSTR(&VAR1,1,5)) vs %SUBSTR(&VAR1,1,5)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

%SYSFUNC(SUBSTR(&VAR1,1,5)) vs %SUBSTR(&VAR1,1,5)

[ Edited ]

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!


Accepted Solutions
Solution
‎10-31-2017 06:48 AM
Super User
Posts: 6,622

Re: %SYSFUNC(SUBSTR(&VAR1,1,5)) vs %SUBSTR(&VAR1,1,5)

Posted in reply to ShagilImam

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

View solution in original post


All Replies
Super User
Posts: 9,855

Re: %SYSFUNC(SUBSTR(&VAR1,1,5)) vs %SUBSTR(&VAR1,1,5)

Posted in reply to ShagilImam

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎10-31-2017 06:48 AM
Super User
Posts: 6,622

Re: %SYSFUNC(SUBSTR(&VAR1,1,5)) vs %SUBSTR(&VAR1,1,5)

Posted in reply to ShagilImam

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 318 views
  • 0 likes
  • 3 in conversation