|
Rarely, macro quoting
functions alter the tokenization of text enclosed in them. Use the %UNQUOTE Function.
|
||
|
&, it searches the macro symbol tables for a matching macro variable
entry. If it finds a matching entry, it pulls the associated text
from the symbol table and replaces &name on the input stack. A macro
variable name is passed to the macro processor, but the processor
does not find a matching entry in the symbol tables. So, it leaves
the token on the input stack and generates this message:
%macro totinv(var);
data inv;
retain total 0;
set sasuser.houses end=final;
total=total+&var;
if final then call symput("macvar",put(total,dollar14.2));
run;
%put **** TOTAL=&macvar ****;
%mend totinv;
%totinv(price)
%put **** TOTAL=&macvar ****; /* ERROR */TOTAL=&macvar to the log, as follows:
TOTAL= $1,240,800.00 WARNING: Apparent symbolic reference MACVAR not resolved. **** TOTAL=&macvar ****
%macro rooms;
/* other macro statements& */
%put **** %str(John's office) ****; /* ERROR */
%mend rooms;
%roomsyes.
%let sr_age = 0;
data senior;
set census;
if age > 65 then
do;
call symput("sr_age",age);
put "This data set contains data about a person";
put "who is &sr_age years old."; /* ERROR */
end;
run;%let sr_age = 0;
data senior;
set census;
if age > 65 then
do;
call symput("sr_age",age);
stop;
end;
run;
data _null_;
put "This data set contains data about a person";
put "who is &sr_age years old.";
run;data _null_;
retain total 0;
set mydata end=final;
total=total+price;
call symput("macvar",put(total,dollar14.2));
if final then put "*** total=&macvar ***"; /* ERROR */
run;&causes
the word scanner to trigger the macro processor, which looks for a
MACVAR entry in a symbol table. Because such an entry does not exist,
the macro processor generates the warning message. Because the tokens
remain on the input stack, they are transferred to the DATA step compiler.
During DATA step execution, the CALL SYMPUT statement creates the
macro variable MACVAR and assigns a value to it. However, the text
&macvarin the PUT statement occurs
because the text has already been processed while the macro was being
compiled. If you were to resubmit these statements and the macro would
appear to work correctly, but the value of MACVAR would reflect the
value set during the previous execution of the DATA step. This value
can be misleading.
% and &trigger immediate execution or resolution during the compilation
stage of the rest of your SAS code.
WARNING: No logical assign for filename FILENAME. WARNING: Source level autocall is not found or cannot be opened. Autocall has been suspended and OPTION NOMAUTOSOURCE has been set. To use the autocall facility again, set OPTION MAUTOSOURCE. WARNING: Apparent invocation of macro MACRO-NAME not resolved.
.sas (if
your operating system uses file extensions). If you experience problems
with the autocall facility, be sure the macro and filenames match
and the file has the right extension when necessary.
Library Member Member Object Object Date Object
Name Name Type Name Type Object Description Modified Alias
-------------------------------------------------------------------------------------------
WORK SASMACR CATALOG FINDAUTO MACRO 05/28/96
SASDATA SASMACR CATALOG CLAUSE MACRO Count words in clause 05/24/96
SASDATA SASMACR CATALOG CMPRES MACRO CMPRES autocall macro 05/24/96
SASDATA SASMACR CATALOG DATATYP MACRO DATATYP autocall macro 05/24/96
SASDATA SASMACR CATALOG LEFT MACRO LEFT autocall macro 05/24/96
%macro conjunct(word= );
%if &word = and or &word = but or &word = or %then /* ERROR */
%do %put *** &word is a conjunction. ***;
%else
%do %put *** &word is not a conjunction. ***;
%mend conjunct;ERROR: A character operand was found in the %EVAL function or %IF
condition where a numeric operand is required. The condition
was:word = and or &word = but or &word = or
ERROR: The macro will stop executing.%macro conjunct(word= );
%if %bquote(&word) = %str(and) or %bquote(&word) = but or
%bquote(&word) = %str(or) %then
%do %put *** &word is a conjunction. ***;
%else
%do %put *** &word is not a conjunction. ***;
%mend conjunct;