BookmarkSubscribeRSS Feed
Karen_sas11
Calcite | Level 5

Good morning Everyone,

I have a quick question here, assume there is a macro parameter and the var is defined, when I call the macro and I assign a new value to the same var, what it would happen?

Let's take this for example:

%macro houses(dsn=houses, sub=RANCH);
data &dsn;
set sasuser.houses; if style="&sub";
run;
%mend;
%houses (sub=SPLIT);
%houses (dsn=ranch);
%houses (sub=TWOSTORY);

so what's the most recent data set did I create?

 

Thanks!

7 REPLIES 7
novinosrin
Tourmaline | Level 20

so what's the most recent data set did I create?

 

should be the result of  

%houses (sub=TWOSTORY);

i.e  

data houses;
set sasuser.houses; if style="TWOSTORY";
run;
Reeza
Super User

Any reason to not run it and check the log to see what the output is?

 


@Karen_sas11 wrote:

Good morning Everyone,

I have a quick question here, assume there is a macro parameter and the var is defined, when I call the macro and I assign a new value to the same var, what it would happen?

Let's take this for example:

%macro houses(dsn=houses, sub=RANCH);
data &dsn;
set sasuser.houses; if style="&sub";
run;
%mend;
%houses (sub=SPLIT);
%houses (dsn=ranch);
%houses (sub=TWOSTORY);

so what's the most recent data set did I create?

 

Thanks!


 

novinosrin
Tourmaline | Level 20

Hi @Karen_sas11 is it some quiz or certification question? or you are seeking or trying to make the distinction between macro compilation and execution. I think it;s the latter

Reeza
Super User
SASUSER.HOUSES is used in the training courses and prep material.
novinosrin
Tourmaline | Level 20

Aah ok. I didn't know that. Thank you!

Karen_sas11
Calcite | Level 5

@Reeza@novinosrin

Yes I saw many similar questions in the prep paper, so can you tell me the mechanism about it?

In the macro parameter,,,var is local, once it is assigned a value(in the compile stage), even when you call (execute)the macro meanwhile assign a new value(to the same var), it won't work right? The value won't be replaced?

Reeza
Super User

I think of it this way, if you create a macro with parameters in the definition, those are default values. If you call the macro with different parameters, then it overrides the default values. 

 


@Karen_sas11 wrote:

@Reeza@novinosrin

Yes I saw many similar questions in the prep paper, so can you tell me the mechanism about it?

In the macro parameter,,,var is local, once it is assigned a value(in the compile stage), even when you call (execute)the macro meanwhile assign a new value(to the same var), it won't work right? The value won't be replaced?


 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 7 replies
  • 1948 views
  • 2 likes
  • 3 in conversation