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?
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!
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.
Ready to level-up your skills? Choose your own adventure.