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

I am trying to write my first macro and I am having problems manipulating the parameters inside macro. This is the code:

%macro SecondDerivative_New (parlambda, parepsilon);

    m=%sysevalf(&parlambda+&parepsilon); /* this gives an error ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The                                                                  condition was:    lambda+epsilon  */

    result1=%FirstDerivative(parlambda=m);

%mend;

%macro FirstDerivative (parlambda=);

    10/&parlambda+24*(exp(-1*&parlambda))/(1-exp(-1*&parlambda))-28.52;

%mend;

/* call macro */

data;

lambda=0.799;

epsilon=0.001;

%SecondDerivative_New(lambda,epsilon);

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I assume that you have greatly simplified things from a much more complex situation.

Based on what you have shown, macros are completely unnecessary here, but maybe they are needed in a more complex situation...

You cannot add data set variables using %SYSEVALF. You can only add macro variables using %SYSEVALF.

So, &parlambda resolves to lambda (which is not a macro variable, it is a datastep variable). &parepsilon resolves to epsilon (which is not a macro variable, it is a datastep variable).

If your macro is always going to have arguments that resolve to datastep variables, then you simply say

m=&parlambda + &parepsilon;

But as I said, using macros and macro variables in this simple situation is completely unnecessary.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

I assume that you have greatly simplified things from a much more complex situation.

Based on what you have shown, macros are completely unnecessary here, but maybe they are needed in a more complex situation...

You cannot add data set variables using %SYSEVALF. You can only add macro variables using %SYSEVALF.

So, &parlambda resolves to lambda (which is not a macro variable, it is a datastep variable). &parepsilon resolves to epsilon (which is not a macro variable, it is a datastep variable).

If your macro is always going to have arguments that resolve to datastep variables, then you simply say

m=&parlambda + &parepsilon;

But as I said, using macros and macro variables in this simple situation is completely unnecessary.

--
Paige Miller
natmaks
Calcite | Level 5

thank you. Yes, it is just a simplified piece.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 800 views
  • 0 likes
  • 2 in conversation