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?


 

 

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