BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10

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)

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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)

View solution in original post

7 REPLIES 7
Astounding
PROC Star

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.

Reeza
Super User
It's legal, but not a good idea.
SAS_inquisitive
Lapis Lazuli | Level 10

@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.

Astounding
PROC Star

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)
SAS_inquisitive
Lapis Lazuli | Level 10
@Astounding, You are overriding the name of macro variable &ds in inner macro.
Astounding
PROC Star

Yes, while the value in the outer macro remains unchanged.

 

You'll be fine with what you are planning.

Tom
Super User Tom
Super User

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.

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
  • 2130 views
  • 8 likes
  • 4 in conversation