【发布时间】:2021-09-12 23:14:38
【问题描述】:
我在 SAS 中有以下数据集
Id date order amount
101 5/20/2020 1 25
101 5/20/2020 2 25
101 5/20/2020 3 0
101 5/21/2020 1 25
101 5/21/2020 2 25
我需要根据‘Id’、‘Date’和‘Order’添加一个counter only amount=25
Id date order amount Ctr
101 5/20/2020 1 25 1
101 5/20/2020 2 25 2
101 5/20/2020 3 0 0
101 5/21/2020 1 25 1
101 5/21/2020 2 25 2
代码:
Data want:
Set have;
By id date order;
Ctr+1;
If first.id and first.date and first.order) and amount=25 then ctr=1;
Run;
我没有得到想要的结果。任何帮助表示赞赏。
【问题讨论】:
-
您已经有一个订单变量,您可以利用它吗?
if amount = 0 then ctr=0;?
标签: if-statement sas counter increment