BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ShagilImam
Obsidian | Level 7

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

%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

2 REPLIES 2
Kurt_Bremser
Super User

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.

Astounding
PROC Star

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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