BookmarkSubscribeRSS Feed
Tom
Super User Tom
Super User

Someone posted this quesiton on StackOverflow https://stackoverflow.com/questions/34820068/function-style-macros-vs-proc-fcmp-functions  but it is probably better suited for discusion here.

I am considering replacing a lot of function-style macros with FCMP equivalents. Before I go through this process I was wondering what limitations FCMP has compared to function style macros? Has anyone else been through this process and are there any reasons why I would notwant to do this?

My reasons for wanting to do this is to make code easier to read and maintain, and less error-prone. I believe that FCMP functions are easier to read than macro code for most SAS programmers.

 What do people think?

3 REPLIES 3
Tom
Super User Tom
Super User

I am not that familiar with functions build with PROC FCMP, but a SAS macro has one of the most user friendly calling interfaces I have seen.  You do not need to use positional parameters and instead can use names in the macro call.  You can even use the names in the macro call when the macro was defined to support positional parameters.  I would hate to give that up.

LinusH
Tourmaline | Level 20
Not sure about readability. Macros has been around forever, and FCMP is a fairly new concept.
But I would suspect that FCMP functions often is more efficient than their macro counterpart.
Data never sleeps
DirkH
Calcite | Level 5

I promised myself to use FCMP more in the future, but you should beware it is not just another way to write the same thing (it is not sytactic sugar). 

Function-like macros are interpreted before compilation. If you write them inside a data step, the same code is compiled, no mather how many observations you will process.

 

If you call FCMP functions, a call is made for each observation.I expect this to be a serious performance penalty in benchmarks, especially if I see how loosly coupled the logic in and outside the FCMP are.

 

The positive sides I see are:

1. function like macro's can have unexpected side effects. FCMP functions don't (as far as I understand)

2. FCMP functions can run complete procedures or datasteps by calling a macro for each observation of a dataset. See also also http://stackoverflow.com/questions/33817518/sas-how-to-return-a-value-from-a-sas-macro/33830485#3383...

 

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
  • 3 replies
  • 3282 views
  • 0 likes
  • 3 in conversation