BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
jon8
Obsidian | Level 7

Hi everyone,

 

I have got some problems to call macro functions within macro functions.

     For instance, why does that little program returns the following error : ERROR: A character operand was found in the %EVAL function where a numeric operand is required. The condition was: 20+ 50;

 

%macro one(A,B);
     %sysevalf(&A-&B);
%mend one;

%macro two(C);
     %sysevalf(&C. + %one(100,50));
%mend two;

%two(20);

I mean, why is there a ";" after my numeric value? Besides, is there a keyword to return the value of a macro program?

Also, I read that macro function aren't really made for coding in SAS so how do we code in SAS Enterprise Guide?

 

Thanks for all your help in advance.

 

Jonathan

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @jon8,


@jon8 wrote:

why is there a ";" after my numeric value?


It's the semicolon you put (inappropriately) after the %SYSEVALF function call. Just remove it in both cases. Function-style macros typically resolve to a "pure" value and you don't want that to be followed by a semicolon as this would be incorrect syntax in most applications of the macro. Also, to test macro TWO I would use a %PUT statement:

%put %two(20);

 

View solution in original post

5 REPLIES 5
FreelanceReinh
Jade | Level 19

Hi @jon8,


@jon8 wrote:

why is there a ";" after my numeric value?


It's the semicolon you put (inappropriately) after the %SYSEVALF function call. Just remove it in both cases. Function-style macros typically resolve to a "pure" value and you don't want that to be followed by a semicolon as this would be incorrect syntax in most applications of the macro. Also, to test macro TWO I would use a %PUT statement:

%put %two(20);

 

Tom
Super User Tom
Super User

There is a semi-colon because the macro you called generated a semi-colon.  If you want to write a macro that can be use like a "function" then make sure it only generates text that can become part of an expression.  So no statements. And definitely no steps.  The macro language is a text pre-processor, nothing more. So any text the macro emits gets consumed by the down stream user of the text it produces.

%macro one(A,B);
   %sysevalf(&A-&B)
%mend one;

 

You don't really program in Enterprise Guide.  Enterprise Guide is GUI tool to allow you to run SAS code.   It has widgets that help you generate SAS code. You can make process flows to setup the order you want things to happen.  But it is not a programming language.

jon8
Obsidian | Level 7
Ok Thank you so much for your help! Have a Nice day !
ballardw
Super User

Try running this example:

%macro one(A,B);
     %sysevalf(&A-&B)
%mend one;

%macro two(C);
     %sysevalf(&C. + %one(100,50))
%mend two;

%put the value is: %two(20);

You placed a ; in two places it was not desirable if you want to use this way.

In many cases that extra ; would be null statement but in the resolution of %one it becomes part of the returned value.

 

If you want to expose a resolved value the general structure of this sort of macro is

%macro dummy(<parameter list>)
<various logic that uses macro functions only to combine
or calculate assigning a single "value" >
value
%mend

Value, which would likely be macro variable reference such as &theresult , without a semicolon is the value seen by code that calls the function. For this reason it is a good idea to provide a default result 0 or similar for when the parameter list is empty or cannot complete constructing the actual desired result for some reason.

 

I am not sure where this comes from: "Also, I read that macro function aren't really made for coding in SAS so how do we code in SAS Enterprise Guide?".  There may be some bits involved with Enterprise Guide related to the interface but macro functions are part of SAS.

 

 

jon8
Obsidian | Level 7
Thank you very much for much. It really helped me figure out a lot of problems in my macros statements!!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 5 replies
  • 1055 views
  • 7 likes
  • 4 in conversation