產生字元字串的子字串。
類別: | DBCS |
類型: | NLS 巨集函數 |
是字元字串或文字運算式。如果 argument 包含特殊字元或助憶運算子 (如這裡所示),請使用 %QKSUBSTR。
是整數,或所產生整數指定子字串中第一個字元位置的運算式 (文字、邏輯或算術)。如果 position 大於字串中的字元數,則 %KSUBSTR 和 %QKSUBSTR 會發出警告訊息,並傳回 Null 值。
是選用整數,或所產生整數指定子字串中字元數的運算式 (文字、邏輯或算術)。如果 length 大於 argument 中 position 之後的字元數,則 %KSUBSTR 和 %QKSUBSTR 會發出警告訊息,並傳回含有從 position 到字串結尾之字元的子字串。%KSUBSTR 和 %QKSUBSTR 預設會產生含有從 position 到字元字串結尾之字元的字串。
%macro makefref(fileref,file); %if %klength(&fileref) gt 8 %then %let fileref = %ksubstr(&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(%klength(&&msg&i)<40); %let msg&i=%qksubstr(&msg,&start,40); %put Message &i is: &&msg&i; %let i=%eval(&i+1); %let start=%eval(&start+40); %let msg&i=%qksubstr(&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 KSUBSTR: %ksubstr(&c,1,2); %put With QKSUBSTR: %qKsubstr(&c,1,2);
C: &a &b With KSUBSTR: one With QKSUBSTR: &a