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.

SAS Innovate 2025: Register Now

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!

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