BookmarkSubscribeRSS Feed
sandeep12
Fluorite | Level 6

What is the difference between %LOCAL and %GLOBAL?

6 REPLIES 6
Patrick
Opal | Level 21

Copy/paste the exact words below into a Google search:

sas What is the difference between %LOCAL and %GLOBAL

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Also search for macro variable scope.  

Tom
Super User Tom
Super User

They both are used to make sure macro variables are defined. The difference is where they are defined. %GLOBAL will define them in the global symbol table.  %LOCAL will define them in the symbol table for the currently running macro.  Once the current macro finishes running its symbol table disappears.

rinugour
Fluorite | Level 6

% Local is a macro variable defined inside a macro. %Global is a macro variable defined in open code (outside the macro or can use anywhere).

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Incorrect.  local or global indicates the scope of the macro variable.  You can create global macros within a macro for instance.  The default for macro variables created within a macro is local to the macro, however you can explicitly state the macro variable is global, and hence make it available outside.  As that doesn't really work with encapsulation, so default is local.  

 

There is clear guidance in the documentation about this:

http://support.sas.com/documentation/cdl/en/mcrolref/62978/HTML/default/viewer.htm#p1b76sxg9dbcyrn1l...

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 9523 views
  • 3 likes
  • 6 in conversation