SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1065 views
  • 2 likes
  • 3 in conversation