1.scan函数:从字符表达式s中搜取给定的n个单词
word = scan(source,n,delimiters );
(1)如果n为负数,则scan选择字符串中从字符串末尾开始的单词。如果|n|大于字符串中的字数,则scan返回一个空白值。
(2)delimiters可以是blank . 0 then
put line;
index2 = index(line, ':');
put 'index2= ' index2;
if index2 > 0 then
reason = substr(line, index2);
put'reason' reason;
run;
/ 结果如下: /
补充:大小写设置
转变所有的字母:
varu=upcase(argument);
varl=lowcase(argument);
var=propcase(argument)首字母大写;
3.find函数:在您指定的字符串中搜索特定的字符子字符串 。
find(string,substring)
string是要在其中搜索的字符串或字符变量名称,
substring是要在字符串中搜索的字符串。返回substring首次在string中出现的位置,若未找到,则返回0。
startpos指定从 string的何处开始搜索substring,正值从左至右,负值反向。
modifier=i,搜索时忽略大小写,默认区分大小写。
/ find函数应用举例 /
data test3;
string1='1234567890';
pos1=find(string1, '3');put 'pos1=' pos1;string2='c:\\project1\\analysis\\distribution.sas';pos2=find(string2, '\\', -100);put 'pos2=' pos2;string3='the search is case sensitive';pos3=find(string3, 'case');put 'pos3=' pos3;string4='the search is not case sensitive';pos4=find(string4, 'case', 'i');put 'pos4=' pos4;string5=upcase(string4);/*将字符串转换为大写*/pos5=index(string5,'case');put 'pos5=' pos5;run;
/ 结果如下: /
然而两类function之间不同的是:find类function有一些index类function所不具有的功能,包括:
(1)find类可以检索所检索目标的”首次“出现位置;
(2)find类可以指定检索的方向(如:自左向右,自右向左);
(3) find类可以忽略字符串的大小写或末尾的空格。
4.compress函数:用以体剔除或保留特定字符
compress(string)
string指定一个要移除字符的源字符串,
chars指定一栏初始字符,默认它是从string里移除的
modifiers指定一个修饰语,函数的具体功能。如:
/ compress函数应用举例 /
data test4;
string1= sunlights;new1=compress(string1);new2=compress(string1,'s');new3=compress(string1,s,k);/*从源字符串中返回字符s*/new4=compress(string1,s,u);/*从源字符串中将字符s及大写字母剔除*/run;
/ 结果如下: /
补充:
1.只有string,移除空格。
2.只有string,chars时,从source中移除chars。
string,chars,modifiers都有时,modifiers中的k决定保留还是移除。无k时,移除chars加上modifiers指定的。5. cat函数:用以拼接字符串
cat(string1, ... , stringn):连接字符串不去除空格
catt(string1, ... , stringn):去除尾部空格连接
cats(string1, ... , stringn):移除前后空格连接 trim删除右侧空格
catx(separator, string1, ... , stringn):移除首位空格,插入特定字符连接
/*代码相当于: */
cat(of x1-x3) = x1||x2||x3
catt(of x1-x3)= trim(x1)||trim(x2)||trim(x3)
cats(of x1-x3)= trim(left(x1))||trim(left(x2))||trim(left(x3))
catx(sp, of x1-x3)=trim(left(x1))||sp||trim(left(x2))||sp||
trim(left(x3))
/ cat函数应用举例 /
data test5;
length a1 a3 $10 a2 a4 8;a1='aaa';a2=1234;a3='bbb';
a4=5678;
line1=cat(of a1-a4);
put line1;
line2=catx(',',of a1-a4);
put line2;
run;
/ 结果如下 /
Neuralink公司的人脑与人工智能同步技术带来怎样的影响与预期
低成本大容量的QLC SSD的性能和寿命被人质疑
居家养老提质怎样可以加快脚步
教你如何设计Django的样式以及如何添加class
如何加快推进“温州智造”高质量发展?智能制造能给温州带来什么?
SAS:常用字符处理函数介绍
5G还没正式商用,6G又来了?
小鹏G3新能源汽车怎么样,权威测评诠释硬核品质
高通3月6日迎大考 博通收购高通报价跃升至1200亿美元
浅谈智能消防应急照明及疏散指示系统在民用建筑中的应用
一种能够检测光信号并将其转换为电信号的光电器件
Dapp开发及智能合约部署技术
移动电源做UL2056 检测报告有哪些测试要求
如何用万用表测量三线制传感器
科技头条:机器人加快实体店提货速度,三星收购ai公司Kngine
索赔5.2亿?芯片巨头高通专利门
5G时代给手机品牌提出了更高的技术要求
看门狗电路图说明
ETC怎样为智慧交通提供自己的价值
成本不是核心,低功耗联网才是关键?智能门锁4G方案全新变革