var
is stored as a four-byte
variable that has the value text
. If text
were
not enclosed in quotation marks, it would be treated as a variable
name. var2
is stored as a seven-byte
variable that has the value example
. data one; var='text'; text='example'; var2=text; run;
Joan's Report
.
Although the TITLE statement contains a matched pair of double quotation
marks, the title itself does not include these outer quotation marks.
However, the outer quotation marks cause the unmatched single quotation
mark within the text to be interpreted as an apostrophe that is part
of the title text. proc print; title "Joan's Report"; run;
prog
with data
new; x=1; run;
stored as its value. options symbolgen; %let prog=data new; x=1; run;; &prog proc print; run;
25 options symbolgen;
26
27 %let prog=data new; x=1; run;
27 %let prog=data new; x=1; run;
-
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
SYMBOLGEN: Macro variable PROG resolves to data new
28 &prog
29 proc print;
30 run;
NOTE: The data set WORK.NEW has 1 observations and 0 variables.
NOTE: The data set WORK.PROC has 1 observations and 0 variables.
NOTE: The data set WORK.PRINT has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
real time 0.25 seconds
cpu time 0.07 seconds |
prog
has
been assigned a value of data new
. SAS interpreted
the first semicolon as the end of the macro assignment statement.
In this case, we want the semicolon to be part of the macro variable
value, but SAS has no way of knowing that. In this situation, you
need to mask text that you want to assign to a macro variable. That
is, you need to hide the normal meaning of the semicolon from the
macro processor. You can use a macro quoting function to do this.
; + - * / , < > = blank ^ ~ # | LT EQ GT AND OR NOT LE GE NE IN
General form, %STR function:
%STR (argument)
argument
is any combination
of text and macro triggers.
|
prog
that has data
new; x=1; run;
as its value.
%let prog=%str(data new; x=1; run;);
%let prog=data new%str(;) x=1%str(;)run%str(;);
prog
macro
variable. %let s=%str(;); %let prog=data new&s x=1&s
run&s;
data=new;
x=1; run;
to the macro variable prog
.
' " ) (
options symbolgen; %let text=Joan's Report; proc print data=sasuser.courses; where days > 3; title "&text"; run;
75 %let text=Joan's Report; --------- 32 WARNING 32-169: The quoted string currently being processed has become more than 262 characters long. You may have unbalanced quotation marks. |
%let text=%str(Joan%'s Report); %let text=Joan%str(%')s Report;The value of
text
is Joan's
Report
in both cases.
period
and
to assign a value of May&Jun
to it. If
you attempt to use the %STR function in the assignment statement,
SAS interprets the ampersand as a macro trigger and generate a warning
message. You need to use the %NRSTR function instead. %let Period=%str(May&Jun); %put Period resolves to: . %let Period=%nrstr(May&Jun); %put Period resolves to: .
1 %let Period=%str(May&Jun); WARNING: Apparent symbolic reference JUN not resolved. 2 %put Period resolves to &period: WARNING: Apparent symbolic reference JUN not resolved. Period resolves to: May&Jun 3 4 %let Period=%nrstr(May&Jun); 5 %put Period resolves to . Period resolves to: May&Jun |
' " ( ) + - * / < > = ¬ ^ ~ ; , # blank AND OR NOT EQ NE LE LT GE GT IN
'
) to a macro variable.
You used the %STR function to mask the apostrophe. %let text=%str(Joan%'s Report); %let text=Joan%str(%')s Report;
%let text=%bquote(Joan's Report);