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!
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;
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!
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
Aah ok. I didn't know that. Thank you!
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?
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:
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?
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!
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.