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.

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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