2012-08-17 87 views
0

我必須執行以下邏輯到SAS:加入巨大的表

If 
    the product field in Client_lookup table is ‘DC’ 
    and if the client_nbr field in Client_lookup table matches with the client_nbr column in Gforce_Auth table, 
then 
    the first six digits of merchant_number field in Gforce_Auth tables will be compared with the first six digit of current_account_number in the Gforce_Auth tables. 

If it becomes equal, then the In store column = ‘Y’ otherwise it is set to ‘N’. The in store column will be set to null if the client _nbr field is not same in both the tables. 

請讓我知道我可以加入這個兩個表,並同時加入檢查上述條件。

我試着用合併聲明,但沒有奏效。提前致謝。

問候, 的Sudhir

+1

你用什麼代碼來嘗試合併?請發佈您的輸入數據樣本以及您期望的結果。 – itzy 2012-08-17 17:58:40

+0

每個表中有多少行? – 2012-08-18 20:06:49

回答

0

我認爲以下應爲你工作。有更有效的方式來做到這一點,但我認爲這個例子應該更容易遵循。

proc sort data=Client_lookup; 
    by client_nbr; 
proc sort data=Gforce_Auth; 
    by client_nbr; 
run; 

data New_File; 
    merge client_lookup(in=in_client_lookup where=(product = 'DC')) 
     Gforce_Auth (in=in_gforce_auth); 
    by client_nbr; 
    format in_store $1.; 
    format merchant_nbr6 cur_acct_nbr6 $6.; 
    if in_client_lookup and in_gforce_auth then do; 
     merchant_nbr6 = substr(left(merchant_number),1,6); 
     cur_acct_nbr6 = substr(left(current_account_nbr),1,6); 
     if (merchant_nbr6 eq cur_acct_nbr) then in_store = 'Y'; 
     else in_store = 'N'; 
    end; 
    else do; 
     in_store = ' '; 
    end; 
    drop merchant_nbr6 cur_acct_nbr6; 
run