BookmarkSubscribeRSS Feed
SasStatistics
Pyrite | Level 9

If I write a macro of the sort: 

%macro MyMacro(var1 /* This is first description */
				,var2 /*Second Description*/); 

then when using the macro, the following help text appears when calling it: 

SasStatistics_0-1626181923992.png

In this case, the macro and calling the macro is in the same script. 

I have stored my Macros in another script, and then use a %include statement to make them available, then the help text does not appear. Is there any way to achieve this? 


Edit: I am using SAS EG and using Autocall library is not an option. 

12 REPLIES 12
Tom
Super User Tom
Super User

Please clarify what user interface you are using that is popping up that text box.

Are you using SAS/Studio?  Enterprise Guide?  Something else?

SasStatistics
Pyrite | Level 9
I am using SAS Enterprise Guide.
PaigeMiller
Diamond | Level 26

Whatever your user interface is, I am not using it, so I'm not sure if my answer will work, but I think it will.

 

Put your macros into an AUTOCALL library instead of using %INCLUDE to access them, and then I believe you will get the desired pop-up.

--
Paige Miller
SasStatistics
Pyrite | Level 9

I am using SAS Enterprise Guide. 

Autocall I think works (have not tried) but it is not an option in this case. Any ideas? 

PaigeMiller
Diamond | Level 26

Why is AUTOCALL not an option?

--
Paige Miller
SasStatistics
Pyrite | Level 9
Legacy in the company I am working at.

If I have arguments against, I could change it - but currently I have not read about it so no idea. Any strong reasons why include is not preferred over autocall?
PaigeMiller
Diamond | Level 26

@SasStatistics wrote:
Legacy in the company I am working at.

If I have arguments against, I could change it - but currently I have not read about it so no idea. Any strong reasons why include is not preferred over autocall?

Let's suppose you have written a macro named MYMACRO. Then, each time you want to use it via %include, you have to type a command like this:

 

%include "/myserver/myfolder/mysubfolder/mymacro.sas";

That's a lot of typing, don't make any mistakes or your code won't run. And you have to do this in every program where you want to use the macro. And if there are multiple macros that are used, you need to type a %include for each. Lots of possibilities to make a mistake, and slower than using an AUTOCALL library.

 

If you use AUTOCALL, then you never have to type the above, you have to include your AUTOCALL library issuing one command in your AUTOEXEC file (you have to do this once, and never again, and not every time you want to use the macros). Then you type %mymacro (and later %mymacro2, and so on), that's a lot less typing, a lot fewer possibilities to make a mistake, and much faster.

--
Paige Miller
ballardw
Super User

@PaigeMiller wrote:

@SasStatistics wrote:
Legacy in the company I am working at.

If I have arguments against, I could change it - but currently I have not read about it so no idea. Any strong reasons why include is not preferred over autocall?

Let's suppose you have written a macro named MYMACRO. Then, each time you want to use it via %include, you have to type a command like this:

 

%include "/myserver/myfolder/mysubfolder/mymacro.sas";

That's a lot of typing, don't make any mistakes or your code won't run. And you have to do this in every program where you want to use the macro. And if there are multiple macros that are used, you need to type a %include for each. Lots of possibilities to make a mistake, and slower than using an AUTOCALL library.

 

If you use AUTOCALL, then you never have to type the above, you have to include your AUTOCALL library issuing one command in your AUTOEXEC file (you have to do this once, and never again, and not every time you want to use the macros). Then you type %mymacro (and later %mymacro2, and so on), that's a lot less typing, a lot fewer possibilities to make a mistake, and much faster.


Adding to @PaigeMiller's comment. If everyone uses the same shared location for the Autocall library then you can share the macros by name and don't have to pass around files or filenames and paths to reference macros with %include. Though it would be a good idea to have someone in charge for what is allowed in the Autocall library.

 

 

 

Also, you already know that %include files do not do what you want regarding this "documentation" element.

PaigeMiller
Diamond | Level 26

@ballardw wrote:

@PaigeMiller wrote:

@SasStatistics wrote:
Legacy in the company I am working at.

If I have arguments against, I could change it - but currently I have not read about it so no idea. Any strong reasons why include is not preferred over autocall?

Let's suppose you have written a macro named MYMACRO. Then, each time you want to use it via %include, you have to type a command like this:

 

%include "/myserver/myfolder/mysubfolder/mymacro.sas";

That's a lot of typing, don't make any mistakes or your code won't run. And you have to do this in every program where you want to use the macro. And if there are multiple macros that are used, you need to type a %include for each. Lots of possibilities to make a mistake, and slower than using an AUTOCALL library.

 

If you use AUTOCALL, then you never have to type the above, you have to include your AUTOCALL library issuing one command in your AUTOEXEC file (you have to do this once, and never again, and not every time you want to use the macros). Then you type %mymacro (and later %mymacro2, and so on), that's a lot less typing, a lot fewer possibilities to make a mistake, and much faster.


Adding to @PaigeMiller's comment. If everyone uses the same shared location for the Autocall library then you can share the macros by name and don't have to pass around files or filenames and paths to reference macros with %include. Though it would be a good idea to have someone in charge for what is allowed in the Autocall library.


Or if you are squeamish about modifying someone else's AUTOEXEC file (but you shouldn't be), or if you are remote and such modification would be difficult, you can send people one line of code, tell them to put it at the top of their programs when they want to use the AUTOCALL library, and again, no need for all that typing of %INCLUDEs. It's like magic! Don't take my word for it, @ballardw knows what he is talking about.

--
Paige Miller
Cynthia_sas
SAS Super FREQ

Hi:
Your macro program usage is not entirely clear to me. However, you should be able to use a session-compiled macro program within SAS Enterprise Guide. This example worked for me.

Cynthia_sas_0-1626192377084.png



However, I was using &VAR1 and &VAR2 only with %PUT and in a TITLE statement. You defined VAR1 and VAR2 as positional parameters, so that's what my example used. However, that means you always need to specify your variables in that order and you do not have a good way to set defaults using positional parameters.

 

  In "real life" I was taught to always use keyword macro program parameters instead of positional parameters because they allow for better control over the defaults of the macro variable values, as shown below:

Cynthia_sas_1-1626192729838.png

With keyword parameters in the Macro program definition, I set defaults for both &VAR1 and &VAR2, but on invocation, only provided a value for &VAR1, which caused the macro program to use the default value for &VAR2.

 
Cynthia

Tom
Super User Tom
Super User

You defined VAR1 and VAR2 as positional parameters, so that's what my example used. However, that means you always need to specify your variables in that order

Defining a macro to accept parameters by position does not prevent the user from passing them by name.  In which case they can reference them in any order.

%mymacro(var2=abc,var1=xyz)

and you do not have a good way to set defaults using positional parameters.

It is not hard to add defaults in the macro code itself.

%if 0=%length(&var1) %then %let var1=default value;

 

Cynthia_sas
SAS Super FREQ
Hi, Tom:
You are correct. Even if the parameters are originally defined as positional, you can pass them in using their name, which is useful. I was taught to be consistent in the definition and the invocation to make it easier for non-macro programmers to understand what was happening. And you're right, you can code for defaults if you know how to use the Macro facility. But since the OP didn't show what was in his macro program, I wanted to keep my program as simple as possible. The easiest way for beginners to set defaults is to use the name=default parameter method.

Cynthai

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 12 replies
  • 1349 views
  • 5 likes
  • 5 in conversation