マクロのコンパイル時に、定数テキストに含まれている特殊文字やニーモニック演算子をマスクします。
| 種類: | マクロクォーティング関数 |
| 参照項目: | %NRQUOTE関数 |
+ − * / < > = ¬ ^ ~ ; , # blank AND OR NOT EQ NE LE LT GE GT IN
%によりマークされている場合に、その文字をマスクします。
' " ( )
& %
|
引数
|
使用
|
|---|---|
|
引用符の前にあるパーセント記号、%'や%”など
|
引用符付きのパーセント記号
例:%let percent=%str(Jim%'s office);
|
|
丸かっこの前にあるパーセント記号、%(や%)など
|
2つのパーセント記号(%%)
例:%let x=%str(20%%);
|
|
コメント記号付きの文字列、/* や -->など
|
各文字ごとに%STR関数を適用
例:%str(/) %str(*) comment-text %str(*)%str(/)
|
%quote(%str(argument))%let time=%str( now); %put Text followed by the value of time:&time;
Text followed by the value of time: now
%macro words(string);
%local count word;
%let count=1;
%let word=%qscan(&string,&count,%str( ));
%do %while(&word ne);
%let count=%eval(&count+1);
%let word=%qscan(&string,&count,%str( ));
%end;
%let count=%eval(&count-1);
%put The string contains &count words.;
%mend words;
%words(This is a very long string)The string contains 6 words.
%test&testがマクロ呼び出しとして解釈されるのではなく、テキストとしてコンパイルされるように同文字列を保護します。
%macro revrs(string);
%local nstring;
%do i=%length(&string) %to 1 %by -1;
%let nstring=&nstring%qsubstr(&string,&i,1);
%end;
&nstring
%mend revrs;
%macro test;
Two words
%mend test;
%put %nrstr(%test%test) - %revrs(%test%test);1 %macro revrs(string); 2 %local nstring; 3 %do i=%length(&string) %to 1 %by -1; 4 %let nstring=&nstring%qsubstr(&string,&i,1); 5 %end;&nstring 6 %mend revrs; 7 8 %macro test; 9 Two words 10 %mend test; 11 12 %put %nrstr(%test%test) - %revrs(%test%test); %test%test - sdrow owTsdrow owT NOTE:SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414 NOTE:The SAS System used: real time 0.28 seconds cpu time 0.12 seconds