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.

请让我知道如何加入这两个表并在加入时检查上述条件。

我尝试了合并语句,但没有奏效。提前致谢。

问候, 苏迪尔

4

1 回答 1

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
于 2012-08-21T20:35:05.330 回答