DATA Step, Macro, Functions and more

Automatic macro variables as local

Reply
Regular Contributor
Posts: 155

Automatic macro variables as local

Based on some testing I just did in 9.2, it appears that some automatic macro variable can be declared to be local inside a macro. I tested sqlrc and SQL obs. Does anyone know of a comprehensive list of which automatics variables can be local?
Respected Advisor
Posts: 3,799

Re: Automatic macro variables as local

I don't think they are _AUTOMATIC_. They are not printed by %put _AUTOMATIC_;

Since they are not created until the procedure executes, your comment would imply they follow the same rule as any other macro variable, with regards to scope.
Regular Contributor
Posts: 155

Re: Automatic macro variables as local

Posted in reply to data_null__
Hmmm. You are correct. I will have to find it as the person who asked me this claimed that it was listed on the doc site as an automatic macro variable. But I just ran the same check you did and also checked dictionary tables and neither of these are automatic.

Thx!
Respected Advisor
Posts: 3,799

Re: Automatic macro variables as local

This note describes the behavior and calls them automatic. So I guess they are.

http://support.sas.com/kb/4/736.html
Valued Guide
Posts: 2,177

Re: Automatic macro variables as local

my "guess" is that any automatic macro variable to which you can assign a value, could be named on a %LOCAL
&syslast is an example I tried
438 %let syslast = something ;
439 %macro check1( name) ;
440 %local syslast ;
441 %let syslast = nothing ;
442 %put _local_ ;
443 %put &name = &&&name ;
444 %mend ;
445 %check1(syslast) ;
ERROR: Attempt to %LOCAL automatic macro variable SYSLAST.
CHECK1 NAME syslast
syslast = WORK.nothing
446 %put &syslast ;
WORK.nothing

So, that ERROR indicates a rule.
(which almosts demands an exception)

peterC
SAS Employee
Posts: 58

Re: Automatic macro variables as local

Automatic macro variables are created by the macro processor when you invoke SAS. All of them are global except for SYSPBUFF which is local. But, you won't see it listed with a "%put _local_" because that only lists user-generated local macro variables.

Of the automatic macro variables that can be assigned values, they still remain global no matter where you assign the new value...
Ask a Question
Discussion stats
  • 5 replies
  • 212 views
  • 0 likes
  • 4 in conversation