如何在SAS中使用_infle_删除分层程序中的行
在SAS Studio中尝试分层prg 我试图用retain语句作为“标题”来保留买方代码和卖方,并用if/then条件语句来阅读细节,但无法找到一种方法来实现这一点,因为在这种方法中重复使用标签。如何使用内嵌删除重复/嵌入的标签如何在SAS中使用_infle_删除分层程序中的行,sas,delete-row,Sas,Delete Row,在SAS Studio中尝试分层prg 我试图用retain语句作为“标题”来保留买方代码和卖方,并用if/then条件语句来阅读细节,但无法找到一种方法来实现这一点,因为在这种方法中重复使用标签。如何使用内嵌删除重复/嵌入的标签 oucher Vendor Vendor Payment Po Nb Total Total PO Inv Nbr I nv Nbr/Ln Inv Dat e Due Date Inv Amt L
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;
所以我认为你正在尝试做下面的事情 注意双@符号的使用。这行代码将把输入读入名为
\u infle\u
的临时变量。双@符号将阻止输入光标前进。这让我们在决定如何处理该行之前,先“向前看”,看看该行包含哪些内容
还请注意,我们读入了买方和卖方,并保留了值,但我们没有在这些行上输出观察结果,而是等待常规的“事务”类型行输出
如果它是我们想要忽略的一行-即标签,我们只需发出另一条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;
请显示您迄今为止尝试的代码以及失败的地方。代码已添加到原始PostThank。那么,“重复标签”是指样本数据中的5条底线吗?这些都是相同的吗?是的,重复标签指的是底部的5行,是的,它们在整个过程中重复相同的方式。唯一的例外是出现在顶部的标签。顺便说一句,这个文件有3000多行数据。在任何情况下,我都可以复制并粘贴到最上面的一组标签上,然后重新上传文件。谢谢。您也可以在数据步骤中使用
in:
,例如如果没有(_infle\u in:('Date:','Time:',…)
Robert很棒。我现在的问题是,我遇到了数据错误,例如,id号762100有一个详细行项目,而764809有三个详细行项目。@NicholasyOves如果您仍然无法解决新问题,我建议用特定的新问题开始一个新问题。尽量减少代码和示例,以便只提供必要的信息。另外-如果这个答案回答了问题,不要忘记将其标记为“已接受”。@user667489哦,太好了-我没有意识到这一点。通过查看文档,似乎您可以在任何字符比较运算符后面加上:
,尽管我想不出除了“equals”或“in”之外还有什么运算符有意义。