Re: [程式] SAS 字串搜尋
※ 引述《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://www.ptt.cc/bbs/Statistics/M.1431411549.A.C48.html
※ 編輯: MOONY135 (114.35.215.137), 05/12/2015 14:22:56
討論串 (同標題文章)