DATA Step, Macro, Functions and more

How can you create two global macro variables with the same name?

Reply
PROC Star
Posts: 1,325

How can you create two global macro variables with the same name?

This is mostly a teaser question.  Wondering if anyone has a good theory as to how an environment like below could be created, where SAS reports there are 2 global macro variables with the same name and different values.  I'm working on a (much longer) post where I will show how I think it's happening, and will ask more questions there.  Will add a link to that thread in the responses, but was curious as to whether folks had seen this sort of oddity before.

MPRINT(SHOW):   data _null_;
MPRINT(SHOW):   set sashelp.vmacro;
MPRINT(SHOW):   where name='G';
MPRINT(SHOW):   put (name scope offset value)(=);
MPRINT(SHOW):   run;
name=G scope=GLOBAL offset=0 value='TEST'
name=G scope=GLOBAL offset=0 value=GLOBAL

--Q.

PROC Star
Posts: 1,325

Re: How can you create two global macro variables with the same name?

Maybe I failed to pique much interest... Here is a link to the long post where I decribe how I managed to create two global macro variables with the same name, and ask for help in understanding how it happened....

https://communities.sas.com/message/130850

Super User
Posts: 10,046

Re: How can you create two global macro variables with the same name?

SAS is not Object Oriented Programming language - like Java.

PROC Star
Posts: 1,325

Re: How can you create two global macro variables with the same name?

Agreed Ksharp, but not sure I see your point.

Even though SAS is not object-oriented there are still "rules" in SAS's design about what should be unique.  So you can't have two datasets in the same library with the same name, can't have two variables in the same dataset with the same name, can't have two different title1 lines defined at the same time.  In the same way, I don't see how it can make sense for there to be two global macro variables with the same name at the same time.  Seems bug-ish to me.

--Q.

Respected Advisor
Posts: 4,173

Re: How can you create two global macro variables with the same name?

Agree - seems bug-ish to me as well. Suggest you send this one to SAS TechSupport.

Trusted Advisor
Posts: 1,301

Re: How can you create two global macro variables with the same name?

I think you brought this up on SAS-L also.  It is an interesting situation.  Seems to only occur in 9.3 and not in 9.2.  So, it certainly seems as though it is a bug with the scope of programs executed in this unique fashion.

PROC Star
Posts: 1,325

Re: How can you create two global macro variables with the same name?

FriedEgg,

Yes, it's the same issue I brought up on SAS-L.  Just thought I would put it out here as well to collect as much feedback / suggestions as I could, before going to tech support with it.  And was surprised by Ksharp's response.

--Q.

Super User
Posts: 10,046

Re: How can you create two global macro variables with the same name?

HeHe.

I agree with you that you cann't have two variables with the same name wthin the same dataset. Maybe you should contact with Technical Support.

Nowadays, I am learning JAVA (JavaEE) , So it is not problem for OOP. An object ( a macro variable) can have two fields ( values).

Ksharp

Ask a Question
Discussion stats
  • 7 replies
  • 315 views
  • 0 likes
  • 4 in conversation