2017-11-03 7 views
-2

in SAS選択する文字セットが複数ある場合に、包含(または代替)演算子を使用する方法。例えば、have_variable = abd、afg、afd、accおよびwant_variable = abd、afg、afd(abまたはafのみを含む)contains operator or equivilantを使用する

+0

**索引**または**検索機能のための仕事のようなSouinds。 – pinegulf

答えて

0

selectステートメントでリストを使用できます。そのような

あなたもこのようなデータセット文で演算子で使用することができます
proc sql; 
select * from my_table where have_variable in ('abd','afg','afd','acc') and want_variable in ('abd','afg','afd'); 
run; 
quit; 

data want; 
set mydate; 
if have_variable in ('abd','afg','afd','acc') and 
want_variable in ('abd','afg','afd'); 
run; 

あなただけが使用できる2つの文字を含む変数を取得したい場合LIKE:データセットの

proc sql; 
select * from my_table where have_variable like '%ab%' or have_variable like '%af%'; 
run; 

data want; 
set mydate; 
where have_variable like '%ab%' or 
have_variable like '%af%'; 
run; 

よろしく

2

私はその後、一致するものを見つけなければならないリストに参加したまま複数のレコードを持つ2つのテーブルにあなたの持っているとするリストを分割しました。

The final table will look like this

/* Create your input String */ 
data Have; 
have="abd , afg , afd , acc"; 
run; 
data Want ; 
want="abd , afg , afd"; 
run; 
/* Splint Input strings into Multiple Rows */ 
data Have_List; 
    set Have; 
    do i=1 by 0; 
    source=lowcase(scan(have,i,',')); 
    if missing(source) then leave; 
    output; 
    i+1; 
    end; 
    keep source ; 
run; 
data Want_List; 
    set Want; 
    do i=1 by 0; 
    lookup=lowcase(scan(want,i,',')); 
    if missing(lookup) then leave; 
    match='match'; 
    output; 
    i+1; 
    end; 
    keep lookup match; 
run; 
/* Create a SQL left join to lookup the matching values */ 
proc sql; 
create table match as 
select h.source as have , COALESCE(w.match,"no-match") as match 
from have_list h left join want_list w on h.source=w.lookup; 
quit; 
0

あなたが唯一のABまたはAF(任意の場所に文字列でそれらを含んでいるのではなく)で始まるレコードをしたい場合は、あなたはin:が続くことができます。この使用法では、コロンは文字列の最初のn文字を検索するようにSASに指示します。ここでnは比較の長さです(この例では2)。

これは、proc sqlではなく、データステージでのみ機能することに注意してください。

data have; 
input have_var $; 
datalines; 
abd 
afg 
afd 
acc 
; 
run; 

data _null_; 
set have; 
where have_var in: ('ab','af'); 
put _all_; 
run; 
関連する問題