1 【例子】 2 3 data a; 4 arg=‘ABC.DEF(X=Y)‘; 5 word=scan(arg,3); 6 put word; 7 run;/*word:X=Y*/ 8 9 data b; 10 arg=‘ABC.DEF(X=Y)‘; 11 word=scan(arg,-3); 12 put word; 13 run;/*word:ABC*/ 14 15 data c; 16 arg=‘ABC.DEF(X=Y)‘; 17 word=scan(arg,-20); 18 put word; 19 run;/*word:空格*/ 20 21 data d; 22 input Arr $ & 22.; 23 ArrivalGate=scan(Arr,1,‘ ‘); 24 DepartureGate = scan(Arr,2,‘ ‘); 25 put DepartureGate ArrivalGate arr; 26 cards; 27 Arrival DepartureGates 28 29 run; 30 /*结果:ArrivalGate:Arrival;DepartureGate:DepartureGates*/ 31 32 33 data e; 34 input Arr $ & 22.; 35 ArrivalGate=scan(Arr,1,‘ ‘); 36 DepartureGate = scan(Arr,2,‘ ‘); 37 put DepartureGate ArrivalGate arr; 38 cards; 39 Arrival,De d, ssd liu 40 ; 41 run; 42 /*结果:ArrivalGate:Arrival,De;DepartureGate:d, ssd*/
Scan函数
【功能】从字符表达式s中搜取给定的n个单词
【类别】 字符函数
【语法】
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的长度,则该函数返回空格。
【SAS BASE】SCAN函数
时间: 2024-11-05 20:33:25