%str should be used ;) as text rather than as macro statement delimiter,
* quote special tokens such as semicolons, percent signs and ampersands; %let s=%str(semicolon; %percent; &ersand); %put &s;
/* Ian Whitlock: A Serious Look Macro Quoting
http://www2.sas.com/proceedings/sugi28/011-28.pdf
*/
%let v_semicolon = %str(;);
%put v_semicolon >&v_semicolon<; /* semicolon >;< */
/* The following put is executed in
OPEN CODE and throws the following error:
ERROR 180-322: Statement is not valid or
it is used out of proper order.
This is because the line is interpreted as
%put %upcase(semicolon >;<);
*/
%put %upcase(v_semicolon >&v_semicolon<);
/* However, with %qupcase instead of %upcase, the
put can be made: */
%put %qupcase(v_semicolon >&v_semicolon<);
%macro m_semicolon;
%local l_semicolon;
%let l_semicolon = %str(;);
%put %upcase(l_semicolon >&l_semicolon<);
%mend m_semicolon;
/* This works! Apparently because the %put
is executed in CLOSED CODE.*/
%m_semicolon;
%macro oregon_trail(state);
/*
Use str because NE and OR are mnemonics with special meaning to the macro processor
Found in http://www2.sas.com/proceedings/forum2007/152-2007.pdf (Ex_1)
*/
%if &state eq %str(NE) or
&state eq %str(OR) or
&state eq MO or
&state eq KS or
&state eq WY or
&state eq ID
%then
%put The Oregon Trail ran through &state;
%else
%put The Oregon Trail did not run through &state;
%mend oregon_trail;
%oregon_trail(NY);
%oregon_trail(%str(OR));
%oregon_trail(%quote(NE));
%oregon_trail(WY);