- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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