文字列の部分文字列を生成します。
| 種類: | マクロ関数 |
| 参照項目: | %NRBQUOTE関数 |
文字列またはテキスト式を指定します。argumentが次に示すような特殊文字やニーモニック演算子を含んでいる場合、%QSUBSTRを使用します。
部分文字列内の先頭文字の位置を表す整数、またはそのような整数を生成する式(テキスト式、論理式、演算式)です。positionの値が文字列内の文字数よりも大きい場合、%SUBSTR関数および%QSUBSTR関数は警告メッセージを発行し、ヌル値を返します。%EVAL関数が自動的に呼び出されるため、nは数値として扱われます。
部分文字列内の文字数を表すオプション整数、またはそのような整数を生成する式(テキスト式、論理式、演算式)です。lengthの値が、argument内のposition以降にある文字数よりも大きい場合、%SUBSTR関数および%QSUBSTR関数は警告メッセージを発行し、positionから文字列の末尾までの文字を含む部分文字列を返します。デフォルトでは、%SUBSTR関数および%QSUBSTR関数は、positionから文字列の末尾までの文字を含む部分文字列を返します。
%macro makefref(fileref,file);
%if %length(&fileref) gt 8 %then
%let fileref = %substr(&fileref,1,8);
filename &fileref "&file";
%mend makefref;
%makefref(humanresource,/dept/humanresource/report96)FILENAME HUMANRES "/dept/humanresource/report96";
%macro sepmsg(msg);
%let i=1;
%let start=1;
%if %length(&msg)>40 %then
%do;
%do %until(%length(&&msg&i)<40);
%let msg&i=%qsubstr(&msg,&start,40);
%put Message &i is: &&msg&i;
%let i=%eval(&i+1);
%let start=%eval(&start+40);
%let msg&i=%qsubstr(&msg,&start);
%end;
%put Message &i is: &&msg&i;
%end;
%else %put No subdivision was needed.;
%mend sepmsg;
%sepmsg(%nrstr(A character operand was found in the %EVAL function
or %IF condition where a numeric operand is required. A character
operand was found in the %EVAL function or %IF condition where a
numeric operand is required.));Message 1 is:A character operand was found in the %EV Message 2 is:AL function or %IF condition where a nu Message 3 is: meric operand is required.A character Message 4 is: operand was found in the %EVAL function Message 5 is:or %IF condition where a numeric operan Message 6 is: d is required.
%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);
C:&a &b With SUBSTR: one With QSUBSTR:&a