2015-05-21 12 views
1

線嘗試分層PRG在SAS工作室如何使用_infile_在SAS以刪除分層PROG

我想保留買方代碼和供應商有保留聲明爲「頭」,並在閱讀一個if/then條件語句的詳細信息,但不能找出一種方式來處理重複標籤。我如何使用infile刪除重複/嵌入的標籤?

oucher Vendor  Vendor Payment  Po Nb  Total Total  PO Inv 
Nbr I nv Nbr/Ln  Inv Dat e Due Date Inv Amt Ln Nb  Rec'd Dist Inv'd Price Price St 
------------ ---------- --- ----------- ----------- -------------- -------- - --------------- -------- --------- -------------- ------------ --- 
Buyer Code: BLS BETTIE SM ITH          
Vendor: 8444 DAT EX- OHMEDA          
762100 62245094 / 03/04/15 42097 2142.46 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 2142.46 Q 
762101 62243752 / 03/01/15 42094 16001.6 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 16001.6 B 
762690 62247150 / 03/07/15 42100 1790.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1790.38 Q 
762691 62246387 / 03/06/15 42099 1520.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1520.38 Q 
762692 62246386 / 03/06/15 42099 1070.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1070.38 Q 
762693 62246385 / 03/06/15 42099 1075.19 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1075.19 Q 
762694 62246384 / 03/06/15 42099 1115.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1115.38 Q 
763572 62253066 / 03/18/15 42111 890.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 890.38 Q 
763574 62253064 / 03/18/15 42111 540 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 540 Q 
763805 62255278 / 03/21/15 42114 1520.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1520.38 Q 
764809 62260713 / 04/01/15 42125 8190.48 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 3971.88 Q 
     2 Las t Recvd Dat e: 12/19/14  2 7 7 1 3740 3740 Q 
     3 Las t Recvd Dat e: 12/19/14  3 7 7 1 478.59 478.6 Q 
765293 62257450 / 03/26/15 42119 540 264568       P 
     1 Las t Recvd Dat e:  6   1 574.31 540 Q 
765294 62257449 / 03/26/15 42119 720 264568       P 
     1 Las t Recvd Dat e:  6   1 574.31 720 B 
Date: 05/01/ 2015    ST. B ARNABAS O SPITAL   P age : 2 
Time: 8:47am    Pay ables Status E xception R pt For 05/01/20 15  R eport: GARPS ESB 
Voucher Vendor  Vendor Payment  Po Nb  Total Total  PO Inv 
Nbr I nv Nbr/Ln  Inv Dat e Due Date Inv Amt Ln Nb  Rec'd Dist Inv'd Price Price St 
------------ ---------- --- ----------- ----------- -------------- -------- - --------------- -------- --------- 

代碼:

libname niklib '/home/nyioves/Nikfold/'; 
data myfile4 (drop=checkpt); 
length Checkpt $ 5. Vendor $ 30.; 
infile '/home/nyioves/Nikfold/Invoice.txt' missover obs=35; 
retain Code1 BuyerID Vendor; 
input Checkpt $ @; 
    if Checkpt="Buyer" then input Code1 $ BuyerID & $40.; 
    if Checkpt="Vendor" then input Vendor : $30.; 
    else if VoucherNo $ Invno $ seperator $ Vndinvdate mmddyy10. PaymntDue $ InvAmt $ PONum Status1 $/
    num1 Las $ letter $ Recvd $ dat $ echar $ date1 $ nnmbr $ totRecd $ totdist invd 
    poprice invprice st2 $; 
run; 
+1

請顯示您到目前爲止試過的代碼以及它失敗的位置。 –

+0

代碼已經加入到原來的文章 –

+0

謝謝。因此,通過「重複標籤」,您的意思是樣本數據中的5條底線?這些總是一樣的嗎? –

回答

1

所以我認爲你正在試圖做類似下面。

請注意使用double @符號。該行代碼將在輸入中讀入一個名爲_infile_的臨時變量。 double @符號將防止輸入光標進行。這讓我們「展望未來」,看看該行包含的內容,然後我們決定如何處理它。

另請注意,我們讀取了買方和賣方,並保留了這些值,但我們並未輸出這些行的觀察結果,我們等待輸出常規的「交易」類型的行。

如果它是我們想忽略的一行 - 即。標籤,我們只需發出另一條input語句將輸入光標向前移動到下一行。

編輯:我還應該提到,=:運營商類似於'開始與'運營商。它將運算符兩邊的字符串截斷爲最短的字符串長度,然後執行相等性檢查。

data test; 
    length buyer_code vendor $200; 
    retain buyer_code vendor ''; 

    infile datalines truncover ; 
    input @@; 


    if not (_infile_ =: 'Date:') 
    and not (_infile_ =: 'Time:') 
    and not (_infile_ =: 'Voucher') 
    and not (_infile_ =: 'Nbr I') 
    and not (_infile_ =: '-------') 
    then do; 

    if _infile_ =: 'Buyer Code' then do; 
     buyer_code = cats(scan(_infile_,2,':')); 
     input; 
    end; 
    else if _infile_ =: 'Vendor:' then do; 
     vendor = cats(scan(_infile_,2,':')); 
     input; 
    end; 
    else do; 

     /* REPLACE THESE 2 LINES WITH YOUR INPUT STATEMENT TO INPUT OTHER VARIABLES */ 
     input ; 
     x = _infile_; 

     output; 
    end; 
    end; 
    else do; 
    input; * MOVE INPUT CURSOR TO NEXT LINE WITHOUT ASSIGNING ANYTHING; 
    end; 
    datalines; 
Buyer Code: BLS BETTIE SM ITH          
Vendor: 8444 DAT EX- OHMEDA          
762100 62245094 / 03/04/15 42097 2142.46 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 2142.46 Q 
762101 62243752 / 03/01/15 42094 16001.6 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 16001.6 B 
762690 62247150 / 03/07/15 42100 1790.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1790.38 Q 
762691 62246387 / 03/06/15 42099 1520.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1520.38 Q 
762692 62246386 / 03/06/15 42099 1070.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1070.38 Q 
762693 62246385 / 03/06/15 42099 1075.19 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1075.19 Q 
762694 62246384 / 03/06/15 42099 1115.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1115.38 Q 
763572 62253066 / 03/18/15 42111 890.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 890.38 Q 
763574 62253064 / 03/18/15 42111 540 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 540 Q 
763805 62255278 / 03/21/15 42114 1520.38 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 1520.38 Q 
764809 62260713 / 04/01/15 42125 8190.48 264568       P 
     1 Las t Recvd Dat e: 12/19/14  1 7 7 1 3971.88 3971.88 Q 
     2 Las t Recvd Dat e: 12/19/14  2 7 7 1 3740 3740 Q 
     3 Las t Recvd Dat e: 12/19/14  3 7 7 1 478.59 478.6 Q 
765293 62257450 / 03/26/15 42119 540 264568       P 
     1 Las t Recvd Dat e:  6   1 574.31 540 Q 
765294 62257449 / 03/26/15 42119 720 264568       P 
     1 Las t Recvd Dat e:  6   1 574.31 720 B 
Date: 05/01/ 2015    ST. B ARNABAS O SPITAL   P age : 2 
Time: 8:47am    Pay ables Status E xception R pt For 05/01/20 15  R eport: GARPS ESB 
Voucher Vendor  Vendor Payment  Po Nb  Total Total  PO Inv 
Nbr I nv Nbr/Ln  Inv Dat e Due Date Inv Amt Ln Nb  Rec'd Dist Inv'd Price Price St 
------------ ---------- --- ----------- ----------- -------------- -------- - --------------- -------- --------- 
; 
run; 
+1

您也可以在數據步驟中使用'in:' - 例如'如果沒有(_infile_ in:('Date:','Time:',...))' – user667489

+0

Robert太棒了。我現在的問題是我收到數據錯誤,例如ID號762100有一個明細行項目,其中764809有3個明細行項目。 –

+0

@NicholasYioves如果你仍然陷在新問題中,我會建議在具體的新問題上提出一個新問題。儘可能減少代碼和示例,以便提供必要的信息。此外,如果回答問題,請不要忘記將此答案標記爲「已接受」。 –