scan函數: scan(s,n,"char")表示從字串string中以char為分隔符提取第n個字串
功能(function):從字符表達式s中搜取給定的n個單詞
語法(syntax)
1.scan(s,n) n為正數時,從字符s末尾提取n個字符
2.scan(s,n) n為負數時,從字符s開始提取n個字符
3.scan(s,n<,list-of-delimiters>)
如果指定分隔符,則只會按照該分隔符提取。
如果不指定,則按照常用的分隔符拆分,默認分隔符為:空格 . < ( + & ! $ *) ; ^ - / , % | 等之一或組合
注意事項:
1.如果缺失指定的生成變量的長度,系統默認長度為200.
2.如果|n|=0或大於字符s的長度,則該函數返回空格。
例如:
data a; arg='ABC.DEF(X=Y)'; word=scan(arg,3); /*輸出X=Y*/ put word; run; data b; arg='ABC.DEF(X=Y)'; word=scan(arg,-3); /*輸出ABC*/ put word; run; data c; arg='ABC.DEF(X=Y)'; word=scan(arg,-20); /*輸出為空*/ put word; run; data d; input str $ & 22.; a=scan(str,1,' '); b=scan(str,2,' '); put a b ; /*abcd efghijklmn */ cards; abcd efghijklmn ; run;
