如何在 SAS 中使用 _infile_ 删除分层程序中的行
how to use _infile_ in SAS to delete lines in a hierarchical prog
在 SAS Studio 中尝试分层 prg
我正在尝试使用 "headers" 保留语句保留买方代码和供应商,并使用 if/then 条件语句详细阅读,但无法找到执行此操作的方法有重复的标签。如何使用 infile 删除 repeating/imbedded 标签?
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 & .;
if Checkpt="Vendor" then input Vendor : .;
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;
所以我认为您正在尝试执行以下操作。
注意双@符号的使用。该行代码会将输入读入名为 _infile_
的临时变量中。双@ 符号将阻止输入光标前进。这让我们 'look ahead' 在决定如何处理它之前先查看该行包含的内容。
另请注意,我们读取了买家和供应商,并保留了这些值,但我们不输出这些行的观察结果,我们等待常规 'transaction' 类型的行输出。
如果这是我们想要忽略的行 - 即。标签,我们只需发出另一个 input
语句将输入光标向前移动到下一行。
编辑:我还应该提到 =:
运算符类似于 'begins-with' 运算符。它将运算符两边的两个字符串截断为最短字符串长度,然后执行相等性检查。
data test;
length buyer_code vendor 0;
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;
在 SAS Studio 中尝试分层 prg
我正在尝试使用 "headers" 保留语句保留买方代码和供应商,并使用 if/then 条件语句详细阅读,但无法找到执行此操作的方法有重复的标签。如何使用 infile 删除 repeating/imbedded 标签?
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 & .;
if Checkpt="Vendor" then input Vendor : .;
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;
所以我认为您正在尝试执行以下操作。
注意双@符号的使用。该行代码会将输入读入名为 _infile_
的临时变量中。双@ 符号将阻止输入光标前进。这让我们 'look ahead' 在决定如何处理它之前先查看该行包含的内容。
另请注意,我们读取了买家和供应商,并保留了这些值,但我们不输出这些行的观察结果,我们等待常规 'transaction' 类型的行输出。
如果这是我们想要忽略的行 - 即。标签,我们只需发出另一个 input
语句将输入光标向前移动到下一行。
编辑:我还应该提到 =:
运算符类似于 'begins-with' 运算符。它将运算符两边的两个字符串截断为最短字符串长度,然后执行相等性检查。
data test;
length buyer_code vendor 0;
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;