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

I am looking at some programs. I realised the same macro gen_base appeared in a different way. One has two paramenters

%macro gen_base(Portf,dev)

 

in another program, I see the following:

%macro gen_base(Portfolo)

 

and the code in the programs gen_base(Portf,dev) and 

gen_base(Portfolo)

 are very different. my question is if they are different how can sas tell which one to use? by identifying one or two variables specified? or is this bad practice to name in such a way?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@HeatherNewton wrote:

we actually have the whole macro written out from %macro to %mend then follow by the line %gen_base straight after the macro code. So it will be using whatever is in the code above it, right? so even if same name, different parameters, it does not matter as long as it is called straight after the macro code included, right?


Right.

 

I think two different macros with the exact same name is something I would avoid, as it causes these types of problems. You will note, for example, that SAS did not create two different PROC MEANS, with different syntax and different purposes. There's only one PROC MEANS, and PROC UNIVARIATE does a lot of the same things that PROC MEANS does, but it also does some different things, and requires different syntax than PROC MEANS, and so a new name is warranted.

 

You would be wise to follow that example. Give your two macros different names.

--
Paige Miller

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

If you supply less parameters than defined, the remaining parameters will be set to empty during macro execution, without causing a NOTE, WARNING or ERROR.

PaigeMiller
Diamond | Level 26

These two different macros named GEN_BASE can't be used by SAS until you specifically include them in your SAS session somehow. There are several methods of including them, including running the code in your current SAS session, by using %INCLUDE, and by setting up an AUTOCALL library.

 

For the first two (running the code in your current SAS session and %INCLUDE), whichever version of the code is included last will be used. If you use an autocall library, there is a specific order (check the documentation) in which the library is searched, and whichever version of the macro is last in the search order will be used.

--
Paige Miller
HeatherNewton
Quartz | Level 8

we actually have the whole macro written out from %macro to %mend then follow by the line %gen_base straight after the macro code. So it will be using whatever is in the code above it, right? so even if same name, different parameters, it does not matter as long as it is called straight after the macro code included, right?

Kurt_Bremser
Super User

@HeatherNewton wrote:

we actually have the whole macro written out from %macro to %mend then follow by the line %gen_base straight after the macro code. So it will be using whatever is in the code above it, right? so even if same name, different parameters, it does not matter as long as it is called straight after the macro code included, right?


Exactly. If the macro call follows the definition immediately, you can't get the wrong one. The old definition will simply be "overwritten" in the store of currently compiled macros.

PaigeMiller
Diamond | Level 26

@HeatherNewton wrote:

we actually have the whole macro written out from %macro to %mend then follow by the line %gen_base straight after the macro code. So it will be using whatever is in the code above it, right? so even if same name, different parameters, it does not matter as long as it is called straight after the macro code included, right?


Right.

 

I think two different macros with the exact same name is something I would avoid, as it causes these types of problems. You will note, for example, that SAS did not create two different PROC MEANS, with different syntax and different purposes. There's only one PROC MEANS, and PROC UNIVARIATE does a lot of the same things that PROC MEANS does, but it also does some different things, and requires different syntax than PROC MEANS, and so a new name is warranted.

 

You would be wise to follow that example. Give your two macros different names.

--
Paige Miller

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 25. 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
  • 5 replies
  • 749 views
  • 2 likes
  • 3 in conversation