BookmarkSubscribeRSS Feed
Tap222
Calcite | Level 5

%sysfunc - why this function we use?

2 REPLIES 2
Reeza
Super User

Documentation:

Execute SAS functions or user-written functions.

 

Logic:

How does SAS macro processing know if text you type is a string or a function? Wrapping it with SYSFUNC tells the processor that you want to evaluate that function, not treat it as a string.

%let my_func = substr(Awesome, 1, 2);
%let my_func_executed = %sysfunc(substr(Awesome, 1, 3));

%put &my_func;
%put &my_func_executed;

Results:

 

 

54 %let my_func = substr(Awesome, 1, 2);
55 %let my_func_executed = %sysfunc(substr(Awesome, 1, 3));
56
57 %put &my_func;
substr(Awesome, 1, 2)
58 %put &my_func_executed;
Awe
Astounding
PROC Star

Macro language contains just a handful of functions.  DATA steps, on the other hand, contain hundreds of functions.  %SYSFUNC was invented so that you could tell macro language to use a DATA step function.  That way, the macro language would not have to reprogram all those DATA step functions into a macro language version.  Most DATA step functions (not all) can be called using %SYSFUNC.

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
  • 984 views
  • 5 likes
  • 3 in conversation