text
. If text
were
not enclosed in quotation marks, it would be treated as a variable
name. Var2 is stored as a 7-byte variable that has
the value example
.
data one; var='text'; text='example'; var2=text; run;
proc print; title "Joan's Report"; run;
; + - * / , < > = blank ^ ~ # | LT EQ GT AND OR NOT LE GE NE IN
Syntax, %STR function:
%STR (argument)
argument
is any combination
of text and macro triggers.
|
' " ) (
options symbolgen; %let text=Joan's Report; proc print data=certadvadv.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;
Joan's
Report
in both cases.
Syntax, %NRSTR function:
%NRSTR (character-string)
Note: The maximum level of nesting
for the macro quoting functions is 10.
|
May&Jun
to
it. If you use the %STR function in the assignment statement, SAS
interprets the ampersand as a macro trigger and generates a warning
message. You must 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
Syntax, %SUPERQ function:
%SUPERQ (argument)
argument
is the name of either
a macro variable with no leading ampersand or an expression that produces
the name of a macro variable with no leading ampersand.
|
data _null_; call symputx('mv1','Smith&Jones'); call symputx('mv2','%macro abc;'); run; %let testmv1=%superq(mv1); %let testmv2=%superq(mv2); %put Macro variable TESTMV1 is &testmv1; %put Macro variable TESTMV2 is &testmv2;
102 %let testmv1=%superq(mv1); 103 %let testmv2=%superq(mv2); 104 %put Macro variable TESTMV1 is &testmv1; Macro variable TESTMV1 is Smith&Jones 105 %put Macro variable TESTMV2 is &testmv2; Macro variable TESTMV2 is %macro abc;
&, %, ', ", ( ), + ,− ,* ,/ ,< >, =, ¬, ^, ~, ; , #, blank,
AND, OR, NOT, EQ, NE, LE, LT, GE, GT, IN
Syntax, %BQUOTE function:
%BQUOTE (character
string | text expression)
character string | text
expression
accepts any text including
macro triggers.
|
data _null_; call symputx('text',"Sally's Seashell Store at Old Towne's Beach"); run; data _null_; put "%bquote(&text)"; run;
Sally's Seashell Store at Old Towne's Beach
Function Name
|
Description
|
---|---|
%QUPCASE
|
converts values to uppercase
|
%QSUBSTR
|
extracts a substring
from a character string
|
%QSCAN
|
extracts a word from
a character string
|
%QSYSFUNC
|
executes a DATA step
function and returns formatted results
|
%let a=%nrstr(Address&name);
%put QUPCASE produces: %qupcase(&a);
QUPCASE produces: ADDRESS&NAME
%let a=one; %let b=two; %let c=%nrstr(&a &b); %put C: &c; %put With SUBSTR: %substr(&c,1,2); %put With QSUBSTR: %qsubstr(&c,1,2);
&a
&b
. In the second %PUT statement, the %SUBSTR
function extracts the value &a
from
the resolved value of the macro variable reference &c, and resolves
&a to 1
. The third %PUT statement
shows that the %QSUBSTR function prevents the value &a
from
being resolved further. 11 %let a=one; 12 %let b=two; 13 %let c=%nrstr(&a &b); 14 15 %put C: &c; C: &a &b 16 %put With SUBSTR: %substr(&c,1,2); With SUBSTR: one 17 %put With QSUBSTR: %qsubstr(&c,1,2); With QSUBSTR: &a
%macro a; aaaaaa %mend a; %macro b; bbbbbb %mend b; %macro c; cccccc %mend c; %let x=%nrstr(%a*%b*%c); %put X: &x %put The third word in X, with SCAN: %scan(&x,3,*); %put The third word in X, with QSCAN: %qscan(&x,3,*);
The third word in X, with SCAN: cccccc The third word in X, with QSCAN: %c
title "Report Produced on %sysfunc(left(%qsysfunc(today(),worddate.)))";
Report Produced on June 4, 2019