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

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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