作者MOONY135 (谈无慾)
标题Re: [程式] SAS 字串搜寻
时间Tue May 12 14:19:06 2015
※ 引述《LinRungChuan (吉他手)》之铭言:
: ------------------------------------------------------------------------
: [软体程式类别]:SAS
: [程式问题]:资料处理
: [软体熟悉度]:一年
: [问题叙述]:
: 有两张table (table A 跟table B)
: 每张各有一个column (SubStr 在table A 跟 FullStr 在table B)
: SubStr 里面的资料 有些会是 FullStr 的部分字元, 该如何取出这些observation
: 例如,
: SubStr FullStr
: abc pabcp
: def ppdefppp
: ghi pjklp
: abcp
: ppppabcpp
: pmnop
: defppp
: 我想取出的资料为
: pabcp
: ppdefppp
: abcp
: ppppabcpp
: defppp
: 若是单一 一个几串 我都用index找, 例如index(FullStr, 'abc')
: 但一整个column index好像 不管怎麽回传都是0, 也试过 用string array
: 把array放到 index里面 例如index(FullStr, Arr{1}) 但也是回传0
: 有人知道 用啥方式可以达到我要的table吗
: 感谢
: -----------------------------------------------------------------------------
proc sql noprint;
select distinct Sub_Str
into :Sub_name1-
from INFOMES.SUB_DATA
;
quit; /*把所有字丢进全域变数*/
data final; /*创造第一个档 让後续的档案APPEND*/
set INFOMES.full_DATA;
where Full_Str contains "&Sub_name1";
run;
%macro add_table; /*从Sub_name2开始做档案*/
%do i=2 %to &sqlobs;
data step&i;
set INFOMES.full_DATA;
where Full_Str contains "&&Sub_name&i";
run;
data final; /*原始的档并上後续的资料*/
set final step&i;
run;
PROC SQL NOPRINT; /*丢掉已经append的档案*/
DROP table step&i;
QUIT;
%end;
%mend add_table;
%add_table
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.35.215.137
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Statistics/M.1431411549.A.C48.html
※ 编辑: MOONY135 (114.35.215.137), 05/12/2015 14:22:56