Tutorial on MACRO Internals Processing

Tutorial on MACRO Internals Processing
Bernie Ruane- SAS Institute
Author: Lynn H. Patrick. SAS Institute Inc.
ABSTRACT
Once the basic concepts have been .astered.
understanding the internals is the next logical
step to enhancing your knowledge of the SASII
lIacro Facility.
stat...ent". ) The facility is also useful for
process1n& infozaation froll your .yst.... The
term .yst.... in this instance. refers to both
your operating system a"
well
as
your
application .yst.... There are aut_tic . .cro
variables which sllow you to obtain information
from the operating system. &SYSJOBID for
ex...ple.
Special symbolic variables are also
available .for letting you obtain information
from the SAS Display lIanager System as well as
design additional features for display ..anager.
In addition.
functions are available for
allowing you to obtain information from the DATA
step and pass information back to it. These are
only a few of the tasks that the macro facility
gives you the capability to implemant.
This tutorial addresses the internals by
identifying
the
components
of
the ..acro
processor. illustrating their relationships with
each other and their interactions with the SAS
supervisor. and examining how a macro program is
processed. lIajor components include the input
stack, wordscanner, word queue, macro compiler,
macro executer, symbolic substituter and open
code
handler.
Special
topics
in
.. acro
procE'ssing
include the performing of symbolic
substitution, resolution, evaluation,
and unquoting. and autocall processing.
quoting
As the macro facility is only a part of the SAS
system I the lIIacro processor must interact with
the other components of the SAS supervisor. The
SAS code generated by your ..acros IlUSt be
syntactically correct. that is it .... t follow
the same rules and constraints that source code
you would enter directly ..ust follow. As you
will see in 'lIacro Processing'. the SAS compiler
cannot distinguish between code generated by the
macro processor and the source lines you
explicitly key into your progr....
Statement
boundary rules. as well as other constructs of
SAS proceSSing. remain unchanged.
The SAS
processor performs sequential execution. that is
the code for a step is compiled until the step
is complete. and then the step is executed.
Text generated from an executing macro.' must be
in the correct step sequence. If a PROC step is
'generated by a lIacro invoked in the middle of a
compiling DATA' step. the PROC step will end the
compilation of the DATA step at that point. The
DATA step code follOWing the lIacro invocation is
then flagged with syntax errors.
Before you can fully understand . .cro processiq
it is essential that you understand the basics
of SAS processiq. as the aero processor is
only an extension of the SAS processor. The
ajor .....ponents and their roles. as well as
their interactions within the system.
i.
reviewed in order to give you a clear
understanding of how processing is done.
INTRODUCTION
The ..acro facility. which has been available
since the 82.3 version of the SAS® Software
System. gives you the capability of enhancing
your SAS programming. The facility has added
many new feat.ures and much func.tionality to the
SAS syste... in addition to allowing you the
opportunity to implement your own features. It
is illlportant. to remember however. that the macro
facility is a part of the SAS system and the
macro processor works with the other components
of the SAS supervisor.
At. times the concept of the macro processor
being a part of the SAS supervisor is forgotten.
Often. users attempt to change the bas ic
structure of SAS processing by writing macros
they think will accomplish this task. The macro
facility is not ..agic. It does not 'change the
way that the SAS compiler and SAS executer
handle your code.
The lIlacro processor does
allow you to control hOI< your code is to be
generated. allOWing you greater flexibility and
IIOre advanced features.
The concept behind the ..acro facility is that it
is a tool. The facility is not a 'packaged'
product. it is a programming language within the
SAS language. The lIacro facility has added many
features and capabilities to the SAS language.
It allows you to build complex applications.
design menuing systems. and provide your own
extensions to present SAS software. One of its
Simplest uses. generating text strings. is often
used to avoid repetition of the same SAS
statements and to allow you to conditionally
execute SAS statements (and portions of SAS
SAS PROCESSING
The input stack is the first component in
processing your program. Your lines of source
are brought into the system for processing
through the input stack. on a line per line
basis.
Because your code is processed in
I t.okens I ,
when the request for a token i.
286
triaaer (percent alan or
curr.ntly oecupyin& tha
word quaua. TIIa type of
the type of triaaer that.
nc:.1vM. tb. woruC:llllller tok.ni.... br••1ta
.ourc:. liD.. .part word by word. 8J\d ......
word. or tokau. OIIe .t •
to tb.
word ....u..
TIl. word qu.u. b
• .ix-word
c:h.nnal tbrou,h whic:h tok.n. are .ade .v.il.bl.
to otb.r C:OIIpOIl.nU of the syn.. for' futb.r
proc:e.. ln,.
ti...
til...
gpersand) in the token
fift.h poslUon of the
action t.k8J\ depends on
.... found.
. Handling of Ampe,...nda
If the triller is 8J\ upenand, the sYilbolic
substitution routine is callad. TIIis routine
18tediately builds hia own word queue, in ..hieh
to copy the bott.OID three words of the ori,inal
word queue. The a)'IDbolic substitution .anaaer
is then called t.o locate the envirOllllent
c:ontainina the nalle in the la.t. position of the
..ord queue.
Token. ~. tbrou,h the word queu.. on. by one.
as the tok.n in the Urst position is r.quest.d
by the syn... 8J\other token enters fr.. the
bott... pushin& tokens alr ••dy in the qu.... up
by on. po.ition. If the IIACRO .yn•• opti.... is
in .ff.c:t ••dditional activity occurs witllin the
word qu.u.. TIle word qu.ue .analer. 8J\Other
word.eann.r comPonent. c:heeks .aeh token .s it
enure position five (fr.... position six) for
.peei.l triller, indieatin, .aero activity.
TII•• e tri&ler. .re the '_persand (&) 8J\d the
percent sip (\).
TIle c:urrant referencinl envirOllllent., the aYilbol
table established by the c:urrently executin,
.aero is cheeked first. If tbe variable is not
tbere, the next-outer envirODlDent, or symbol
teble, is c:heelted. TIIis envir_t would be
the alobal referaneina envirODllent, .stablished
durin& SAS invocation, if the exeecutin& . .cro
was not invoked inside another .acro. U tbere
was
a nested
invocation,
the next-outer
envirOlllDent would be that of the next-outer
.aero. The outerlllOst environment will always be
the alobal anvironment.
An upere8J\d (&) token indicates a possible
sYilbolie reference and that the sYilbolie
sub.titution
routine
.hould
be
called.
Sillilarly. a percent (~) token indicates that
'the word ... y be a macro invocat.ion or .aero
keyword and thn the open code handler should be
c:alled. When the above routines are ~alled. the
token is acted upon, (this action is described
in '1I.c.ro Processin,I), and the result., emitted
by the lIaero facility is placed onto the top of
the input stack. (Remember that the token could
have indicated an action to be taken by the
.. aero facility,
where no text would be
,enerated.) Occupyinl the top element of the
input .taek, the resu It is passed throulh the
words canner for tokenization and the first token
i. plac:ed into the bottom poSition of the
ori,inal word queue. As the next token enters
the queue, the next to last word is c:hecked for
.aero trillers.
If ,one is found, the .acro
proc:essor is called (symbolic substitution or
the open c:ode handler.) If no trill~rs are
found, the ..ords c:ontinue to move up throulh the
queue, one position at a tilDe, until each
reaches the top position. As the tokens advance
from the top position, each is passed to the SAS
eompil er .
If the name is
located in one of the symbol
tables, symbolic substitution places its value
into his ..ork area and then advances his ..ord
queue in search of another symbolic reference.
This continues until tbere are no more adjacent
symbolic references.
When this point
is
reached,
symbolic substitution pushes
his
results (t.he contents of his work area) onto the
input. stack . and removes the words that
constituted the initial triller frOID the
or ilina 1 word queue.
If the name is not· found in any of t.he symbol
tables,
symbolic substitution produces
no
results and
the orilinal word queue is
undisturbed. If the SERROR system option is in
effect, symbolic substitution also issues the
follOlo"ing message.
WARNING 1301:
TIle compiler checks to see i f the token
represents a step boundary.
(Step boundaries
eonsist of PROC statements, the DATA atat. .ent,
the RUN statement, the CARDS statement and the
PARIICARDS statelDent..) If the token is a step
bound.ry, then c:ompilation of the current step
is ended. TIle step is then passed to the SAS
exeeuter. The next step then bel ins to eOlDpile
as soon as execution of the previous step is
COIIpleted.
APPAREI\'T SYMBOLIC REFERENCE
UNRESOLVED
Handling of pereent.
the Uiaaer found in the next to last
po. i tion of tbe word queue is a percent 15 ian,
the open c:ode handler is called. This routine
builds his .""." word queue into ..hich he c:opies
the bott.. three words fr.... the orilinel ..ord
queue. The open c:ode handlers c:heelts tbe ..ord
in the last position to see i f it is a reaerved
word. If it is, t.be routine which perforlDs the
apec,ific action is called.
(Two of these
routines,
resolution
and
.valuation
are
discussed
in
'Special
Topics
in
lIacro
hoeessina' ) .
If
When the compiled step is passed to the SAS
exeeuter, the appropriate DATA step or PROC
routine ia called.
MACRO PROCESSING
If t.he last ..ord in t.he queue is IlACRO, the open
code bandler reeoanizes that the beginnina of a
.acro definition is oecurinl. He then call. the
.acro COIIpiler.
The . .ero COIIpiler build. bia
own word queue from the last cokens in the word
TIle proeesI5ina done by the macro facility belins
when the ..ord queue .analer recopi.es • ..ero
2f57
Queue of the open c:ode handler.
The .ac:ro
C:ODIpiler c:ontinu.. to advanc:e his word Queue,
C:""'P11111& the tokens, unUl he enc:ounters the
perc:ent sian followed by IlEND. Durill& the UlDe
he is c:ompiling, .ac:ro program stateaents are
c:hec:ked for ayntax and are C:""'Piled, SAS aourc:e
statements are stored as text.
The c:ompiled
.ac:ro 1a atored on disk, and the table of
C:""'Piled .ac:ros is updated to include the name
of the newly c:olDpiled lDac:ro.
statisUc:a by depart8eDt for "eekly aale.
infonaation. 111e uer reque.U", the repOrt has
asked that he aee the obaervations and ......ry
atatisUc:a to,ether, for each depart8ent. You
dec:ide to use the PRINT and MEANS proc_dure. for
this applic:etion, lout realize you will Deed to
invoke the.e procedures aultiple tilDes in order
to ,roup the output es requested. If you subset
the data aet ha.ed on the value. of DEPT, the
variable repre••ntiq depart.ent nllllber, and
invoke the procedures on each aubset the
application 1s silllple. The only problem is that
you will have to aodify the progr.. eac:h ti.e a
departaent is added or removed. Usiq the .ac:ro
facility,
the process
c:an ba autOllated,
regardless of departments that . .y be added in
the future. The followiq example illustrates
one .ethod of c:odin& this application.
If the open c:ode hanJiler finds a reserved word;
other than ,""CRO, it c:alls the nec:essary
routine to perform the action. If the token is
not a reserved word, the open c:ode handler
c:hec:ks to aee if i t is the nalDe of a lDacro that
the uaer has defined. He then c:alls the lDacro
executer who processes macro program statement.s
and places generated SAS c:ode on the input
stack.
If the name was not found, the open code handler
then checks to see i f the autocall facility is
in effect.
(Processing done by autocall is
disc:ussed in ' Autocall Process ing , ) .
If the
autoc:all facilty is not in place, the open code
handler leaves the words in the Queue of the
open code handler undisturbed.
If the SAS
system pption,
HERROR J
is in effect,
1* Set up .acro variables to represent
1* the values of DepartlDent *1
PROC SORT DATA=LIB.DPTSALES;
BY DEPT;
he then
DATA NULL;
SET-LIB. DPTSALES END=EOF;
BY DEPT;
IF FIRST.DEPT THE!'
DO;
N+l;
CALL SYllPUT(' DEP' II LEFT(N) ,DEPT);
issues the following lDessage.
WARKING 1353:
*'
APPARE!>.' MACRO I"VOCATIOK
NOT FOU"D
END;
IF EOF THE!'
CALL SYllPUT( 'TOT' ,LEFT(N»;
RUN;
SPECIAL TOPICS IN MACRO PROCESSING
Cert.ain areas of macro processing tend· to be
more complex or at least less obvious than
others.
Five of these areas are symbolic
1* Desian the . .cro Gensys,
*f
1* to perform the applic:ation *1
substitution, especially. when symbolic values
return symbolic values J resolution, evaluation,
quoting and unquoting, and autocall processing.
,""CRO GENSYS;
SOO 1=1 \;TO &TOT;
DATA TEIIP;
SET LIB.DPTSALES;
IF DEPT=&&DEP&I;
Symbolic Substitution
The
process
o(
symbolic
substit.ution
is
basic:ally described in 'Handling of Amperands'.
It is reemphasized here.in order to sh ...· thn
even though the symbol iC reference may gro.· in
complexity, the ac:tual silllplicity of the routine
remains the same. In lDany applications it is
often useful for one symbolic reference to yield
another .ymbolic referenc:e. This is often done
by adding additional upersands to the front of
the .acro variable reference (or references in
c:ase. of c:oDc:atanation.) It is important to
reaember two basic c:oncepts here. First of all,
an aapersand 1BIediately followed by another
upersand (with no space in between) will always
resolve to a single ampersand when processed by
the .ac:ro facility. Secondly when tokens are
c:oDcatenated, they are processed from left to
ri,ht. Consider the followin& application.
Suppose
listing
RUN;
PROC PRINT;
TITLE "SALES OISERVATIONS FOR DEPAImIEIIT
RUN;
WoDEP&I";
PROC !lEANS;
TITLE "SUIIIIARY OF SALES FOR DEPAImIEIIT
RUN;
66oDEP&I":
\;END;
JllEND GENSYS;
The fint step in the applic:ation is to read the
input data set, and set up . .c:ro variables to
represent e.c:h value of depertaent.
Thi. is
you are asked to produc:e a report
......ry
observations
and
.ales
288
builds his word queue, copying the bottom three
words. He place. the value of &DEPI onto the
input stack ....d removes the & and DEPI from the
original word queue. The tokenizer then passes
this result (the first value of department) to
the word queue.
done by udna the FIRST. ..thod to entar a DO
loop each ti.e the BY value chanaes. TIle DO
loop first incr ....nts a counter. "'. by one each
ti.e the FIRST. condition is lIet. This counter
is then left justified. converted to a character
strina ....d concatenated onto the literal 'DEP'.
The current value of DEPT i8 then a .. iped to
the .acro variable. The END= option is used on
the SET statement in order to establish when the
end of the fUe is reached. When this condition
is .et. the last value for N is assianed to the
.acro variable TOT.
Since the number of
department values will often be unknown, TOT can
be used whenever this information is needed.
The second reference to &&DEP&I is enclosed in
double quotes as part of a text string on the
TITLE statement.
Remember that a text string
enclosed in single or double quotes is processed
as one token. When this token enters the word
queue. it b
recopized .s a double quoted
literal. The word queue manager cans a special
routine to handle double quoted literals. the
resolve routine. (This routine is also used to
execute the RESOLVE data step function.)
The . .cond step defines the .. acro GENSYS to
perform
the
application.
The
~
loop,
incrementing I by one each tillle through the
loop, will generan the steps to perform the
application, the number "of times speCified by
the macro variable TOT. In the first execution
of the loop, the DATA step subsets the input
data set, i f DEPT is equal to the first by value
represented by &&DEP&I.
PRoe PRIJI.'T A!\D PRoe
!lEA.I(S are then invoked on the data set, TEMP.
This process is repeated each time the loop is
incremented, ""ith the value of &1 reflecLing
...hich BY value is being used.
Notice that a
different title will also be generated for each
execution of the loop.
The process
for
evaluating &&DEP&I .. ay appear complex, but you
will see that it is simply the same process of
symbolic substitution.
Resolution builds a word queue in which to
proces.s the literal.
He simply takes in a
string, ...d generates a string.
&&DEP&I is
recognized by the word queue ..... ager and
processed
by symbolic
substitution
before
entering the word queue of resolve. The words
inside the text string continue to move through
this word queue until the string is complete.
Remember that tokens enteriDg the resolve word
queue, require no additional action.
Evaluation
The evaluation routine works very III&ch like the
resolve routine. It also only processed tokens
that require no further action. When eval is
called, be builds a word queue and receives
tokens from ttle word queue manager.
Remember
that this routine only sees the actual elements
he will compare. Any other type of action is
performed beforA tokens enter his queue. In the
expression
How is &&DEP&I evaluated?
Remember that the
tokenizer breaks the string into tokens as it is
taken from the input stack. These tokens are
then passed into the word queue one by one.
Consider the first reference to &&DEP&I, on the
DATA step IF statement. At the time the first
ampersand reaches the next to last position· of
the word queue, the preceding equal sip is
occupying the position immediately above. The
ampersand triggers symbolic. substitution who
builds his own word queue and copies the bottom
three words from the ·original word queue.
He
then finds an ampersand in the last position.
Symbolic substitution evaluates && as &, and
places & in his work area. He then advances his
word queue.
~VAL(&A+l)
the tokens that enter the word queue are the
value of &A, +, and 1. Eval then performs the
addition and pushes the result back onto the
input stack.
An important concept to remember is that the
same evaluation routine handles bot.h implicit.
and explicit evaluation.
Explicit. evaluation
occurs when you use the 'U:VAL function.
This
function should be used when you are trying to
assign a
numeric value
requ1r1ng integer
arit.hmetic or t.he result of a comparison (0 or
1) to a macro variable.
It should not be used
on either s ide of the operator on a ~IF
statement, in the numeric positions O:{l a ~O
statement, or in the numeric positions
macro
functions. In all of these places evaluation is
implicitly done for you. If you do use UVAL in
these places, the evaluat.ion routine is called
twice.
The next word. DEP, enters t.he queue.
As there
is no act.ion to perform on the t.oken as it
enters the Dext position, he copies DEP into the
work area (beside the &.) The next token to
IIOve up is the ampersand.
As the ampers and
reaches the next to last pOSition, and I enters
the last position, &1 is evaluated as I, (the
first tille through the ~ loop) and the 1 is
placed into the work area. Advancing the queue
again, symbolic substitution finds a blank. He
then pushes the results in his work area onto
the input stack and removes the initial trigger
from the original word queue (the equal sigo is
not disturbed.)
0'
Quoting .nd Unquoting
QuotiJIg functions, the most· mystical part of the
.acro lanauaae are as essential to aacro
programming as the quotation marks in the SAS
language. The need for quoting is obvious from
the simple example below.
The top element on the input stack is now the
string &DEPI. The words canner passes the words
& and DEPl to the word queue. When the & IIOves
from the last to the next to last position,
symbolic substitution is c.ned.
He .gain
DATA;
289
characurs to _ proceaaed vitllout t_ ullll
""'inas or acUOli -ilia taen. ID order for
the _anini of a quoted character to _
restored. the delta character nst be replaced
with the or1&inll char.cter.
In ~his .xUlpte, ~he value of II is :s; How would
you liter.lly a.sian II the value of 1+27 Quite
s18ply, JOU would quote it.
Unquotin&. or r .....vin. ~h. delta character ,.
perfor.ed is pedor.ed ~wo differe..t ways.
Unquotin& is pedorMd axplicitly by tb.
~ function.
This function Ihould be used
whe.. you have quoted aapecial charlcter and
want to restore its Upificance for further
processiD& by ~h. . .cro facility. UnquotiD. of
delta char.curs il also done automaUeally as
the ~oken palses froll ~he fourth to ~he tbircl
pod Uon i .. ~he word queue.
DATA;
X·'1+2' ;
PL"T XK;
In ~his second exUlple, the value value of X is
Uurally 1+2. Why is quotin, neces . . ry in the
.acro f.ciUty if ~he facUity only processes
atri...s'
It is ....ential bec.use ~he .acro
facility also has ~he need ~o 'take thin,s
U~erally' .
The .acro facility did not use
quotation .arks. as the SAS l.n,uale has already
est.bUshed •• aninl for these.
A lIeans for
quo~ina 'pecifically for the - .acro faciHty was
.. eeded.
",utocan ProceSSing
The autocall facility allows you ~o invoke
. .eros that will be compiled on a demand basis .
·That is. unle .. you actually invoke a .acro. it
does ..ot aet COIIpiled. Thls feature h.s two
obvious advantales.
It 1& 8IOre efficient. io
that a system that can e"ecute one to any oWllher
of .acros depending on user response. nO" wi 11
only cOlllpile those .acros that are actually
invoked.
It also .akes the fact that you are
using .. acros less obvious to the users t who .ay
not even reeopize they ere usina them.
For lack of a .ood spedal character to
substitute (due to restricted meaninls and
different keyboards). the decision "as ... de to
belin a literal "ith ~STR( and to close it "ith
).
~TR
was the initial quotinl function
~ritten
for the macro facility.
is used to remove the silnificance from all
special characters except ampersands and percent
~STR
Autocall works by havinl you place the aource
code for your .acro defiDitions in ..e.bers
havina the sue D.... as ~he . .eros they contain.
in parti Honed data sets ·under OS/MYS end
.aclibs
under
YII/CIIS.
The
library
(or
concatenated libraries) is then referenced by
usiq the LIBNAIIE specified by the SASAUTOS=
.yst.... option. In order for the .acro facility
to recognize that autocall .acros are av.ilable.
the IlAllTOSOURCE system option- .ust also be .i..
effect.
Another function, ~'~STR, ~8S ~ri~ten to
also quot.e these characters.
~STR and ~t\RSTR
are not executed by the macro processor, instead
these functions are components of tokenization.
The)· .re recognized by the tokenizer just as
single or double quotes are. Because ~STR and
~"RSTR are both ". function of tokenization, they
onl)· remove the significance from special
charact.ers in their actual argument..
As you
kn~', tokenizat.ion occurs before macro execution
or symbolic subst.it.ut.ion.
A means of quoting
special charact.ers occuring as a result of
resolution or execution ~8S needed.
sign~.
Guidelines to follow in usin& the autocall
facility are ,enerally ~o use ,cod judameDt in
planning the macro libraries. It is a good idea
'to place t.he sourc.e c.ode for 'liacros int.o 'the
autocall library only after tbey have heeu
tested and debulled. It is also a ,cod idea to
only put autocall .acros ill this library. Be
careful when c.hoosing names for the lIacros,
especially if they are defilled as statement
style .acros.
You do ..ot waot the.. confused
with other functIons or keywords.
The first quoting funct.ion .·rit-t.en for this
purpose was \QUOTE.
It removes significance
from tbe ....e apecial characters· as UTR. The
difference is that \QUOTE is executed by the
.acro processor during lIlacro execution and
symbolic substitution.
It is used to quote
characters in values that are unknown unt 11
.acro execution has occured. ~QUOTE ~as added
to work in the same way as \QUOTE. but to also
work on uperaands end percent signs.
Addinl
~he capability of quotinl unanticipated special
characters was the purpose behind UQUOTE and
'lNRBQUOTE .
The i ..stallation t.ape JOUr aite receives
provides you with an autocall library supplied
by SAS Institute IDe. The SAS clist. exec. and
cataloaued procedure are already .et up ~o
referellce ~his library. Under TSO. you can us.
the AUTOS p.r....ter of the SAS clist to specify
your library ....... Illvoking the clist as
Addi... ~be capability of quoting all these
cbaract.ra
durin& .aero execution without
.ttUPtinl ~o resolve eny .acro variable
references or . .ero invocations was the reason
for add in, ~SUPERQ. This function is actually
an autocall "cro, shipped on the installation
~ape.
UUPERQ uses an a different routine.
. .tasym for retrievin& symbolic values.
.
SAS AUTOS(IIY.IlACLIB)
automatically allocates your .acro library.
concate.. aU..g it in front of ~he .yst.... level
library. You ean also allocate· other libraries
with
differeDt LIBNAllEs.
end
chan,e
~he
SASAUTOSK aystem option to reflect which library
you are workiq with.
Quoti.... or removin, the significance of special
characters. is done by replacin& the char_cur
with a delta char.cter.
Thil allows the
290
Under 0&, 70u can aupply a IASAtTI'OS DD n n ....nt
to CDn.:atenau your Ubrary with the a~at . .
Ubrary. If you do 1I0t .:on.:nenate the library,
your allo.:ation ~ill ov.rrid. that of the ayst ..
library.
, o.tworlt of auto.:all . ..:ro libraries caD
provide your pro,r_ra Dd user. with .any
additional capabiliti... "ulUple librari •• can
be .:oncatanated, usually with the user level
firat, th.n die ayst_ l.vel .t the site, Dd
then the library suppUed by the Institute.
Under CIIS, you .:an IIOdify your version of the
SAS .xec on your A disk, to conc.tenne your
library in front of the Institute auppli.d
library. Remember to add your ... clib Due to
the GLOBAL eutuent": as well.
You.:an also
FlUDEF 70ur .a.:lib, ,lobel it, and aet the
IASAtTI'OS- .yat. . option appropriately. This.:an
... dODe "'fore or after illvoltinS the SAS ne.:.
CONCLUSION
If you have attempted to use the lIacro fac11tiy
and found it diffi.:uIt r .....ber that a ,ood
\lIIderatandill,. of the lAS syatem ia important
before .any of the . ..:ro I:ODcepta are claar. ,
bowledae of .acro processina will .alte your
proar"",s easier to desian, implement, and debuS.
Topics 1n macro processing wi 11 be':Dlle dear
with lIore use of the facility. Remember that
the macro facility is provided as a tool with
which you .:an enhance your own applications, 1t
is • progr ..... inl lanluage within the SAS
lensuale .
Undentandina the pro.:e.. iq dooe by the .acro
f • .:ility when autocaU is used will help 70u to
Wle the fa.:iUty IIOre e.sily and efficiently.
Whell a sU inS of the fOri! U i. encountered by
the open .:ode haDdler, r ..ember that it 1e first
I:bal:lted asainst the list of reserved words. If
1t is Dot found, the striDS 1s then dlecked
. . .1ost the COIIIpiled lIacro list.
If it is not
there, the open code handler .:hecks to eee if
autocall is active, the I1AUTOSOURCE option is in
effect. If it' is, the open code handler then
.:he.:ks to see if the SASAUTOS= library has been
defined.
If not,
the fo 11"", ins error i.
,enerated.
Further information on these topics can be found
in The SAS Guide to Macro Processing(%, 1987
Edition
ERROR 1354: SOURCE LEVEL AUTOCALL DDl\AME NOT
FO~~ OR CANNOT BE OPENED.
AUTOCAL1 HAS BEE" SUSPEI\DED.
If you are running interactively, you can then
al :o.:ate the library and reset the I1AUTOSOURCE
option.
You will need to invoke the macro
a,ain.
If the library has been defined, autocall wi 11
brin& the source code from the library member of
t.he same name into the system. All the source
c.ode in
the member)
including the macro
defintion, is compiled. As soon as the code in
the .ember has been compiled, the invoked macro
will be executed. Usually, the only source code
in t.he member is the mac.ro definition, but
occasionally you may want to include ot.her macro
definitions or even additional SAS code.
In using autoeall there are certain concepts you
want to remember.
First, autocalling
.acros is more efficient than using the ~INClude
statement to br ing in the source code for your
.aeros. Autoc811 was written for this purpose
alone, and performs open and c.lose routines
specifically for autocall. The lIacro facility
will never autocall a macro that bas already
been compiled. This can pose a problem when the
. .cro you have autocalled contains a syntax
error. One way to correct an error is to use
~he INC ':OIDIIIand on ~he display .. anager cOllllland
lille to bring the mellber into the program edit
wind~·.
Edit the macro, correcting your error.
Use the SAVE command, with the REP option to
place the corrected _ber 10 the library .
TheD, submit the source code from the prosram
editor window and reinvoke the macro.
The
ayetem "ill recompile the macro frOOl your
aource.
Remember, it is sUllested that you
deboa your .acros before placing them 10 the
~ill
291