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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1101 views
  • 8 likes
  • 4 in conversation