立即打开
    
 
    
    
    
        
    
 
                                        
全文请参见:
http://crackman.net/?p=1257
如何去发现一个包含有多个word的字符变量,是否包含某一个word,我们一般有find函数
以及index函数,这两个方法来处理
第一个:这里需要对变量进行大写化处理
proc freq data=sashelp.zipcode;
where index(upcase(statename),”ISLAND”) > 0;
tables statename;
title1 “Count for each ‘Island’ area”;
run;
第二个方法:
采用find函数(SAS9.X)支持的新函数
proc freq data=sashelp.zipcode;
where find(statename,”Island”,”i”) > 0;
tables statename;
title1 “Count for each ‘Island’ area”;
run;
Count for each ‘Island’ area 1
2011年03月05日 星期六 下午05时57分39秒
FREQ PROCEDURE
Full name of state/territory
累积 累积
STATENAME 频数 百分比 频数 百分比
———————————————————————
Northern Mariana Islands 3 2.73 3 2.73
Rhode Island 91 82.73 94 85.45
Virgin Islands 16 14.55 110 100.00
看看find函数的介绍:通过几个例子来说明一下
EX1:最简单的用法,就是用在She sells seashells? Yes, she does.寻找第一个独立的she这个单词在哪个位置,返回的是27
说明she这个word出现在上面这段字符串中第27个字符处。
data crackman;
whereisshe=find(‘She sells seashells? Yes, she does.’,'she ‘);
put whereisshe;
run;
EX2:注意这里的’I'参数是忽略要查询单词中字符的大小写差异
data crackman;
variable1=’She sells seashells? Yes, she does.’;
variable2=’she ‘;
variable3=’i';
whereisshe_i=find(variable1,variable2,variable3);
put whereisshe_i;
run;
EX3:
data crackman;
expression1=’She sells seashells? ‘||’Yes, she does.’;
expression2=kscan(‘he or she’,3)||’ ‘;
expression3=trim(‘t ‘);
whereisshe_t=find(expression1,expression2,expression3);
put whereisshe_t;
run;
这里其实对t这个参数的解释,如果有t这个参数表示的是忽略要查询和被查询字符串中的前后空格符对于查询匹配的影响,例如第一个例子里面
因为没有t参数,所以结果是27,这里结果是14,也就是在seashe…中的she进行匹配的
其他更多的情参考help文档

                                         
                                     
 
 
扫码加我 拉你入群
请注明:姓名-公司-职位
以便审核进群资格,未注明则拒绝
 
 
 
 
   
  全部回复
  
 
 
 
 
 
 
 
 
扫码加我 拉你入群
请注明:姓名-公司-职位
以便审核进群资格,未注明则拒绝
 
 
 
 
   
  
相关推荐
栏目导航
热门文章
推荐文章
 
 
    
扫码加好友,拉您进群