Hello,
Is it legal to use same parameter in both outer and inner macro here?
%macro inner (ds = );
proc print data = &ds.;
run;
%mend;
%macro outer (ds =);
%inner(ds = &ds.);
%mend outer;
%outer (ds = sashelp.class)
You'll be fine. Do you understand the results that this variation would create?
%macro inner (ds = );
proc print data = &ds.;
run;
%let ds = temp;
%put Inner DS is &DS;
%mend;
%macro outer (ds =);
%inner(ds = &ds.);
%put outer DS is &DS;
%mend outer;
%outer (ds = sashelp.class)
It is legal.
It should be avoided unless absolutely necessary. It becomes difficult to tell what &DS refers to, since the values in the inner and outer macros do not have to match.
@Astounding @Reeza . Thanks. In my case the macro variable value is same in both outer and inner. I want to add the extra parameter in outer macro for further processing.
You'll be fine. Do you understand the results that this variation would create?
%macro inner (ds = );
proc print data = &ds.;
run;
%let ds = temp;
%put Inner DS is &DS;
%mend;
%macro outer (ds =);
%inner(ds = &ds.);
%put outer DS is &DS;
%mend outer;
%outer (ds = sashelp.class)
Yes, while the value in the outer macro remains unchanged.
You'll be fine with what you are planning.
Yes.
Not sure why some are saying it is not desirable. Use the same name if it makes the code easier to understand, or use different names if that makes more sense.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.